put back caption for multi-page longtable in latex
diff --git a/NAMESPACE b/NAMESPACE
index 722b28b..7d42cb5 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -25,6 +25,7 @@
 importFrom(stringr,str_match_all)
 importFrom(stringr,str_replace_all)
 importFrom(stringr,str_split)
+importFrom(stringr,str_sub)
 importFrom(stringr,str_trim)
 importFrom(utils,read.csv)
 importFrom(xml2,"xml_attr<-")
diff --git a/R/kableExtra-package.R b/R/kableExtra-package.R
index 72978fb..a753a32 100644
--- a/R/kableExtra-package.R
+++ b/R/kableExtra-package.R
@@ -1,7 +1,7 @@
 #' kableExtra
 #'
 #' @importFrom stringr str_count str_split str_match str_detect str_match_all
-#' str_extract str_replace_all str_trim str_extract_all
+#' str_extract str_replace_all str_trim str_extract_all str_sub
 #' @importFrom xml2 read_xml xml_attr xml_has_attr xml_attr<- read_html
 #' xml_child xml_children xml_name xml_add_sibling xml_add_child xml_text
 #' xml_text<-
diff --git a/R/kable_styling.R b/R/kable_styling.R
index e68f01a..1dce2be 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -169,7 +169,7 @@
                              position = c("center", "left", "right",
                                           "float_left", "float_right"),
                              font_size = NULL,
-                             repeat_header_text = "\\ldots continued") {
+                             repeat_header_text = "(continued)") {
 
   latex_options <- match.arg(
     latex_options,
@@ -248,10 +248,19 @@
     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,
-    "}\\\\"
-  )
+
+  if (is.na(table_info$caption)) {
+    continue_line <- paste0(
+      "\\multicolumn{", table_info$ncol, "}{@{}l}{", repeat_header_text,
+      "}\\\\"
+    )
+  } else {
+    continue_line <- paste0(
+      "\\caption{", table_info$caption, " ", repeat_header_text,
+      "}\\\\"
+    )
+  }
+
   x <- c(
     x[1:header_rows_end],
     "\\endfirsthead",
diff --git a/R/magic_mirror.R b/R/magic_mirror.R
index e00032c..7b35e74 100644
--- a/R/magic_mirror.R
+++ b/R/magic_mirror.R
@@ -58,6 +58,7 @@
   kable_info$ncol <- nchar(kable_info$align)
   # Caption
   kable_info$caption <- str_match(kable_input, "caption\\{(.*?)\\n")[2]
+  kable_info$caption <- str_sub(kable_info$caption, 1, -4)
   # N of rows
   kable_info$nrow <- str_count(kable_input, "\\\\\n") -
     # in the dev version (currently as of 11.2015) of knitr, when longtable is
diff --git a/tests/visual_tests/longtable.Rmd b/tests/visual_tests/longtable.Rmd
index 7755f7c..382e81e 100644
--- a/tests/visual_tests/longtable.Rmd
+++ b/tests/visual_tests/longtable.Rmd
@@ -22,7 +22,13 @@
 ```
 
 ```{r}
-kable(dt, "latex", longtable = T, caption="test table", booktabs = T) %>%
+aaa <- kable(dt, "latex", longtable = T, caption="table2", booktabs = T) %>%
   add_header_above(c(" ", "a" = 6, "b" = 5)) %>%
-  kable_styling(latex_options = "repeat_header", repeat_header_text = "Table 2 cont.")
+  kable_styling(latex_options = "repeat_header", repeat_header_text = "(...)")
+```
+
+```{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.)")
 ```