complete documentations for changes
diff --git a/R/kable_styling.R b/R/kable_styling.R
index bf2da86..a824d77 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -33,7 +33,10 @@
#' 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
+#' @param ... extra options for HTML or LaTeX. For LaTeX, extra options includes
+#' `repeat_header_method` and `repeat_header_text`. `repeat_header_method` can
+#' either be `append`(default) or `replace` while `repeat_header_text` is just a
+#' text string you want to append on or replace the caption.
#'
#' @examples x_html <- knitr::kable(head(mtcars), "html")
#' kable_styling(x_html, "striped", position = "left", font_size = 7)
@@ -168,7 +171,8 @@
position = c("center", "left", "right",
"float_left", "float_right"),
font_size = NULL,
- repeat_header_text = "\\textit{(continued)}") {
+ repeat_header_text = "\\textit{(continued)}",
+ repeat_header_method = c("append", "replace")) {
latex_options <- match.arg(
latex_options,
@@ -176,6 +180,8 @@
several.ok = T
)
+ repeat_header_method <- match.arg(repeat_header_method)
+
out <- NULL
out <- as.character(kable_input)
table_info <- magic_mirror(kable_input)
@@ -194,7 +200,8 @@
}
if ("repeat_header" %in% latex_options & table_info$tabular == "longtable") {
- out <- styling_latex_repeat_header(out, table_info, repeat_header_text)
+ out <- styling_latex_repeat_header(out, table_info, repeat_header_text,
+ repeat_header_method)
}
if (full_width) {
@@ -241,7 +248,8 @@
sub(table_info$end_tabular, paste0(table_info$end_tabular, "\\}"), x)
}
-styling_latex_repeat_header <- function(x, table_info, repeat_header_text) {
+styling_latex_repeat_header <- function(x, table_info, repeat_header_text,
+ repeat_header_method) {
x <- read_lines(x)
if (table_info$booktabs) {
header_rows_start <- which(x == "\\toprule")[1]
@@ -257,10 +265,10 @@
"}\\\\"
)
} else {
- continue_line <- paste0(
- "\\caption{", table_info$caption, " ", repeat_header_text,
- "}\\\\"
- )
+ if (repeat_header_method == "append") {
+ repeat_header_text <- paste(table_info$caption, repeat_header_text)
+ }
+ continue_line <- paste0("\\caption{", repeat_header_text, "}\\\\")
}
x <- c(
diff --git a/inst/NEWS b/inst/NEWS
index 7554c8c..70009f1 100644
--- a/inst/NEWS
+++ b/inst/NEWS
@@ -17,7 +17,9 @@
don't fulfill XHTML requirements
* For all HTML table functions, improved exportation method to remove the XML
-declaration.
+declaration. (Stackoverflow: https://stackoverflow.com/questions/45262308/knit2wp-adds-text-with-kableextra)
+
+* Add `repeat_header_method` in kable_styling (#25)
kableExtra 0.3.0
diff --git a/man/kable_styling.Rd b/man/kable_styling.Rd
index 52080ae..3c6f766 100644
--- a/man/kable_styling.Rd
+++ b/man/kable_styling.Rd
@@ -44,7 +44,10 @@
\item{font_size}{A numeric input for table font size}
-\item{...}{extra options for HTML or LaTeX}
+\item{...}{extra options for HTML or LaTeX. For LaTeX, extra options includes
+\code{repeat_header_method} and \code{repeat_header_text}. \code{repeat_header_method} can
+either be \code{append}(default) or \code{replace} while \code{repeat_header_text} is just a
+text string you want to append on or replace the caption.}
}
\description{
This function provides a cleaner approach to modify the style