Improved striped-row's looking on tables with multiple header rows. #31
diff --git a/R/kable_styling.R b/R/kable_styling.R
index 9274ea0..b034d36 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -223,11 +223,31 @@
 styling_latex_striped <- function(x, table_info) {
   # gray!6 is the same as shadecolor ({RGB}{248, 248, 248}) in pdf_document
   if (table_info$tabular == "longtable" & !is.na(table_info$caption)) {
-    row_color <- "\\rowcolors{2}{white}{gray!6}\n"
+    row_color <- "\\rowcolors{2}{white}{gray!6}"
   } else {
-    row_color <- "\\rowcolors{2}{gray!6}{white}\n"
+    row_color <- "\\rowcolors{2}{gray!6}{white}"
   }
-  return(paste0(row_color, x, "\n\\rowcolors{2}{white}{white}"))
+
+  x <- read_lines(x)
+  if (table_info$booktabs) {
+    header_rows_start <- which(x == "\\toprule")[1]
+    header_rows_end <- which(x == "\\midrule")[1]
+  } else {
+    header_rows_start <- which(x == "\\hline")[1]
+    header_rows_end <- which(x == "\\hline")[2]
+  }
+
+  x <- c(
+    row_color,
+    x[1:(header_rows_start - 1)],
+    "\\hiderowcolors",
+    x[header_rows_start:header_rows_end],
+    "\\showrowcolors",
+    x[(header_rows_end + 1):length(x)],
+    "\\rowcolors{2}{white}{white}"
+  )
+  x <- paste0(x, collapse = "\n")
+  return(x)
 }
 
 styling_latex_hold_position <- function(x) {
diff --git a/docs/awesome_table_in_pdf.Rmd b/docs/awesome_table_in_pdf.Rmd
index 703944d..44d1181 100644
--- a/docs/awesome_table_in_pdf.Rmd
+++ b/docs/awesome_table_in_pdf.Rmd
@@ -131,7 +131,7 @@
 In fact, if you want to add another row of header on top, please feel free to do so. Also, in kableExtra 0.3.0, you can specify `bold` & `italic` as you do in `row_spec()`.
 ```{r}
 kable(dt, booktabs = T) %>%
-  kable_styling() %>%
+  kable_styling(latex_options = "striped") %>%
   add_header_above(c(" ", "Group 1" = 2, "Group 2" = 2, "Group 3" = 2)) %>%
   add_header_above(c(" ", "Group 4" = 4, "Group 5" = 2)) %>%
   add_header_above(c(" ", "Group 6" = 6), bold = T, italic = T)
diff --git a/docs/awesome_table_in_pdf.pdf b/docs/awesome_table_in_pdf.pdf
index 298ce55..30290cd 100644
--- a/docs/awesome_table_in_pdf.pdf
+++ b/docs/awesome_table_in_pdf.pdf
Binary files differ
diff --git a/inst/NEWS b/inst/NEWS
index e76f4f5..d8a87b4 100644
--- a/inst/NEWS
+++ b/inst/NEWS
@@ -48,6 +48,8 @@
 
 * Improve package-level documentation based on @wibeasley's suggestion
 
+* Improve striped line look on tables with multiple layers of header rows. (#31)
+
 kableExtra 0.2.1
 --------------------------------------------------------------------------------
 
diff --git a/tests/visual_tests/longtable.Rmd b/tests/visual_tests/longtable.Rmd
index 47b1f50..2653dc1 100644
--- a/tests/visual_tests/longtable.Rmd
+++ b/tests/visual_tests/longtable.Rmd
@@ -36,7 +36,7 @@
 ```{r}
 kable(dt, "latex", longtable = T, booktabs = T) %>%
   add_header_above(c(" ", "a" = 6, "b" = 5)) %>%
-  kable_styling(latex_options = "repeat_header", repeat_header_text = "(cont.)")
+  kable_styling(latex_options = c("striped", "repeat_header"), repeat_header_text = "(cont.)")
 ```
 
 ```{r}