Improve the look of continuous table based one #14
diff --git a/DESCRIPTION b/DESCRIPTION
index bb45a25..86caaf4 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -27,7 +27,8 @@
     stringr (>= 1.0),
     xml2,
     rvest,
-    rmarkdown (>= 1.4.0)
+    rmarkdown (>= 1.4.0),
+    readr
 Suggests:
     testthat
 VignetteBuilder: knitr
diff --git a/NAMESPACE b/NAMESPACE
index ca49b9d..722b28b 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -13,6 +13,7 @@
 export(usepackage_latex)
 importFrom(knitr,knit_meta_add)
 importFrom(magrittr,"%>%")
+importFrom(readr,read_lines)
 importFrom(rmarkdown,latex_dependency)
 importFrom(rmarkdown,metadata)
 importFrom(rvest,html_table)
diff --git a/R/kableExtra-package.R b/R/kableExtra-package.R
index 79f77e5..72978fb 100644
--- a/R/kableExtra-package.R
+++ b/R/kableExtra-package.R
@@ -10,6 +10,7 @@
 #' @importFrom rmarkdown latex_dependency
 #' @importFrom magrittr %>%
 #' @importFrom utils read.csv
+#' @importFrom readr read_lines
 #' @name kableExtra-package
 #' @aliases kableExtra
 #' @docType package
diff --git a/R/kable_styling.R b/R/kable_styling.R
index 74f11e1..e68f01a 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -33,6 +33,7 @@
 #' a `LaTeX` table, if `float_*` is selected, `LaTeX` package `wrapfig` will be
 #' imported.
 #' @param font_size A numeric input for table font size
+#' @param ... extra options for HTML or LaTeX
 #'
 #' @examples x_html <- knitr::kable(head(mtcars), "html")
 #' kable_styling(x_html, "striped", position = "left", font_size = 7)
@@ -46,7 +47,8 @@
                           latex_options = "basic",
                           full_width = NULL,
                           position = "center",
-                          font_size = NULL) {
+                          font_size = NULL,
+                          ...) {
 
   if (length(bootstrap_options) == 1 && bootstrap_options == "basic") {
     bootstrap_options <- getOption("kable_styling_bootstrap_options", "basic")
@@ -77,7 +79,7 @@
                              bootstrap_options = bootstrap_options,
                              full_width = full_width,
                              position = position,
-                             font_size = font_size))
+                             font_size = font_size, ...))
   }
   if (kable_format == "latex") {
     if (is.null(full_width)) {
@@ -87,7 +89,7 @@
                             latex_options = latex_options,
                             full_width = full_width,
                             position = position,
-                            font_size = font_size))
+                            font_size = font_size, ...))
   }
 }
 
@@ -166,7 +168,8 @@
                              full_width = F,
                              position = c("center", "left", "right",
                                           "float_left", "float_right"),
-                             font_size = NULL) {
+                             font_size = NULL,
+                             repeat_header_text = "\\ldots continued") {
 
   latex_options <- match.arg(
     latex_options,
@@ -192,7 +195,7 @@
   }
 
   if ("repeat_header" %in% latex_options & table_info$tabular == "longtable") {
-    out <- styling_latex_repeat_header(out, table_info)
+    out <- styling_latex_repeat_header(out, table_info, repeat_header_text)
   }
 
   if (full_width) {
@@ -236,10 +239,29 @@
   sub(table_info$end_tabular, paste0(table_info$end_tabular, "\\}"), x)
 }
 
-styling_latex_repeat_header <- function(x, table_info) {
-  row_one <- table_info$contents[2]
-  new_row_one <- paste0("\\\\endhead\n", row_one)
-  return(sub(row_one, new_row_one, x))
+styling_latex_repeat_header <- function(x, table_info, repeat_header_text) {
+  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]
+  }
+  continue_line <- paste0(
+    "\\multicolumn{", table_info$ncol, "}{@{}l}{", repeat_header_text,
+    "}\\\\"
+  )
+  x <- c(
+    x[1:header_rows_end],
+    "\\endfirsthead",
+    continue_line,
+    x[header_rows_start:header_rows_end],
+    "\\endhead",
+    x[(header_rows_end + 1):length(x)]
+  )
+  x <- paste0(x, collapse = "\n")
+  return(x)
 }
 
 styling_latex_full_width <- function(x, table_info) {
diff --git a/man/kable_styling.Rd b/man/kable_styling.Rd
index 90aca6f..a491d31 100644
--- a/man/kable_styling.Rd
+++ b/man/kable_styling.Rd
@@ -6,7 +6,7 @@
 \usage{
 kable_styling(kable_input, bootstrap_options = "basic",
   latex_options = "basic", full_width = NULL, position = "center",
-  font_size = NULL)
+  font_size = NULL, ...)
 }
 \arguments{
 \item{kable_input}{Output of `knitr::kable()` with `format` specified}
@@ -43,6 +43,8 @@
 imported.}
 
 \item{font_size}{A numeric input for table font size}
+
+\item{...}{extra options for HTML or LaTeX}
 }
 \description{
 This function provides a cleaner approach to modify the style
diff --git a/tests/visual_tests/longtable.Rmd b/tests/visual_tests/longtable.Rmd
index 7070302..7755f7c 100644
--- a/tests/visual_tests/longtable.Rmd
+++ b/tests/visual_tests/longtable.Rmd
@@ -1,6 +1,8 @@
 ---
 title: "Untitled"
-output: pdf_document
+output: 
+  pdf_document:
+    keep_tex: true
 ---
 
 ```{r setup, include=FALSE}
@@ -14,7 +16,13 @@
 
 dt <- rbind(mtcars, mtcars) 
 
-kable(dt, "latex", longtable = T, booktabs = T) %>%
+kable(dt, "latex", longtable = T, caption="test table") %>%
   add_header_above(c(" ", "a" = 6, "b" = 5)) %>%
   kable_styling(latex_options = "repeat_header")
 ```
+
+```{r}
+kable(dt, "latex", longtable = T, caption="test table", booktabs = T) %>%
+  add_header_above(c(" ", "a" = 6, "b" = 5)) %>%
+  kable_styling(latex_options = "repeat_header", repeat_header_text = "Table 2 cont.")
+```