Merge pull request #73 from newtux/master

Fix issue in hold position being used with center default float
diff --git a/NAMESPACE b/NAMESPACE
index 6ec7c1e..d30b54e 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -31,6 +31,7 @@
 importFrom(stringr,str_extract_all)
 importFrom(stringr,str_match)
 importFrom(stringr,str_match_all)
+importFrom(stringr,str_replace)
 importFrom(stringr,str_replace_all)
 importFrom(stringr,str_split)
 importFrom(stringr,str_sub)
diff --git a/R/add_header_above.R b/R/add_header_above.R
index e716b69..62dd0e6 100644
--- a/R/add_header_above.R
+++ b/R/add_header_above.R
@@ -123,9 +123,9 @@
   new_header_split <- pdfTable_new_header_generator(header, table_info$booktabs,
                                                     bold, italic, monospace)
   new_header <- paste0(new_header_split[1], "\n", new_header_split[2])
-  out <- sub(hline_type,
-             paste0(hline_type, "\n", new_header),
-             enc2utf8(as.character(kable_input)))
+  out <- str_replace(enc2utf8(as.character(kable_input)),
+                     hline_type,
+                     paste0(hline_type, "\n", new_header))
   out <- structure(out, format = "latex", class = "knitr_kable")
   # new_header_row <- latex_contents_escape(new_header_split[1])
   if (is.null(table_info$new_header_row)) {
diff --git a/R/kableExtra-package.R b/R/kableExtra-package.R
index 5add5e5..9dc9689 100644
--- a/R/kableExtra-package.R
+++ b/R/kableExtra-package.R
@@ -56,7 +56,7 @@
 #' load related LaTeX packages manually.
 #'
 #' @importFrom stringr str_count str_split str_match str_detect str_match_all
-#' str_extract str_replace_all str_trim str_extract_all str_sub
+#' str_extract str_replace_all str_trim str_extract_all str_sub str_replace
 #' @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_remove write_xml xml_text<-
diff --git a/R/kable_styling.R b/R/kable_styling.R
index 5e00bd3..a2cb9f0 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -180,6 +180,7 @@
                              font_size = NULL,
                              repeat_header_text = "\\textit{(continued)}",
                              repeat_header_method = c("append", "replace"),
+                             repeat_header_continued = FALSE,
                              stripe_color = "gray!6",
                              latex_table_env = NULL) {
 
@@ -215,7 +216,7 @@
 
   if ("repeat_header" %in% latex_options & table_info$tabular == "longtable") {
     out <- styling_latex_repeat_header(out, table_info, repeat_header_text,
-                                       repeat_header_method)
+                                       repeat_header_method, repeat_header_continued)
   }
 
   if (full_width) {
@@ -300,7 +301,8 @@
 }
 
 styling_latex_repeat_header <- function(x, table_info, repeat_header_text,
-                                        repeat_header_method) {
+                                        repeat_header_method,
+                                        repeat_header_continued) {
   x <- read_lines(x)
   if (table_info$booktabs) {
     header_rows_start <- which(x == "\\toprule")[1]
@@ -323,15 +325,38 @@
     continue_line <- paste0("\\caption[]{", repeat_header_text, "}\\\\")
   }
 
-  index_bottomrule <- which(x == "\\bottomrule")
-  x <- x[-index_bottomrule]
-  x[index_bottomrule - 1] <- paste0(x[index_bottomrule - 1], "*\\bottomrule")
+  if (!table_info$booktabs) {
+    bottom_part <- NULL
+  } else {
+    index_bottomrule <- which(x == "\\bottomrule")
+    x <- x[-index_bottomrule]
+
+    if (repeat_header_continued == FALSE) {
+      bottom_part <- "\\endfoot\n\\bottomrule\n\\endlastfoot"
+    } else {
+      if (repeat_header_continued == TRUE) {
+        bottom_text <- "\\textit{(continued \\ldots)}"
+      } else {
+        bottom_text <- repeat_header_continued
+      }
+      bottom_part <- paste0(
+        "\\bottomrule\n",
+        "\\multicolumn{", table_info$ncol, "}{r@{}}{", bottom_text, "}\\\n",
+        "\\endfoot\n",
+        "\\bottomrule\n",
+        "\\endlastfoot"
+      )
+    }
+  }
+
+  # x[index_bottomrule - 1] <- paste0(x[index_bottomrule - 1], "*\\bottomrule")
   x <- c(
     x[1:header_rows_end],
     "\\endfirsthead",
     continue_line,
     x[header_rows_start:header_rows_end],
     "\\endhead",
+    bottom_part,
     x[(header_rows_end + 1):length(x)]
   )
   x <- paste0(x, collapse = "\n")
diff --git a/tests/visual_tests/.gitignore b/tests/visual_tests/.gitignore
index 7ea9e79..c861d1f 100644
--- a/tests/visual_tests/.gitignore
+++ b/tests/visual_tests/.gitignore
@@ -5,3 +5,4 @@
 *.log
 *.tex
 *.synctex.gz
+*.lot
diff --git a/tests/visual_tests/longtable.Rmd b/tests/visual_tests/longtable.Rmd
index 2e3e301..31e9f82 100644
--- a/tests/visual_tests/longtable.Rmd
+++ b/tests/visual_tests/longtable.Rmd
@@ -25,7 +25,8 @@
 
 ```{r}
 kable(dt, "latex", longtable = T, caption = "test", booktabs = T, caption.short = "sss") %>%
-  kable_styling(latex_options = c("striped", "repeat_header"), repeat_header_text = "(...)")
+  kable_styling(latex_options = c("striped", "repeat_header"), 
+                repeat_header_text = "(...)", repeat_header_continued = T)
 ```
 
 ```{r}