Add `repeat_header` to PDF documentation
diff --git a/R/row_spec.R b/R/row_spec.R
index a276b33..81b0190 100644
--- a/R/row_spec.R
+++ b/R/row_spec.R
@@ -29,8 +29,7 @@
return(row_spec_html(kable_input, row, bold, italic))
}
if (kable_format == "latex") {
- message("The LaTeX version of row_spec has not yet been implemented. ")
- return(kable_input)
+ return(row_spec_latex(kable_input, row, bold, italic))
}
}
@@ -64,26 +63,20 @@
return(out)
}
-# row_spec_latex <- function(kable_input, row, bold, italic) {
-# table_info <- magic_mirror(kable_input)
-# align_collapse <- ifelse(table_info$booktabs, "", "\\|")
-# kable_align_old <- paste(table_info$align_vector, collapse = align_collapse)
-#
-# if (bold | italic) {
-# usepackage_latex("array")
-# latex_array_options <- c("\\\\bfseries", "\\\\em")[c(bold, italic)]
-# latex_array_options <- paste0(
-# "\\>\\{", paste(latex_array_options, collapse = ""), "\\}"
-# )
-# table_info$align_vector[row] <- paste0(latex_array_options,
-# table_info$align_vector[row])
-# }
-#
-# kable_align_new <- paste(table_info$align_vector, collapse = align_collapse)
-#
-# out <- sub(kable_align_old, kable_align_new, as.character(kable_input),
-# perl = T)
-# out <- structure(out, format = "latex", class = "knitr_kable")
-# attr(out, "original_kable_meta") <- table_info
-# return(out)
-# }
+row_spec_latex <- function(kable_input, row, bold, italic) {
+ table_info <- magic_mirror(kable_input)
+ target_row <- table_info$contents[row + 1]
+ new_row <- latex_row_cells(target_row)
+ if (bold) {
+ new_row <- paste0("\\{bfseries", new_row, "}")
+ }
+ if (italic) {
+ new_row <- paste0("\\{em", new_row, "}")
+ }
+ new_row <- paste(new_row, collapse = " & ")
+
+ out <- sub(target_row, new_row, as.character(kable_input), perl = T)
+ out <- structure(out, format = "latex", class = "knitr_kable")
+ attr(out, "original_kable_meta") <- table_info
+ return(out)
+}
diff --git a/R/util.R b/R/util.R
index c16b79d..90c84bc 100644
--- a/R/util.R
+++ b/R/util.R
@@ -51,3 +51,7 @@
adjust_numbers <- pc_matrix$adj[pc_matrix$old_id %in% positions]
return(adjust_numbers + positions)
}
+
+latex_row_cells <- function(x) {
+ strsplit(x, " \\& ")
+}
diff --git a/docs/awesome_table_in_pdf.Rmd b/docs/awesome_table_in_pdf.Rmd
index b322c70..dfd6745 100644
--- a/docs/awesome_table_in_pdf.Rmd
+++ b/docs/awesome_table_in_pdf.Rmd
@@ -227,3 +227,17 @@
column_spec(1, bold = T) %>%
column_spec(2, width = "30em")
```
+
+***
+
+The following feature is introduced in `kableExtra` 0.3.0.
+
+# Repeat Header in longtable
+In this release, a new option `repeat_header` was introduced into `kable_styling`. It will add header rows to longtables spanning multiple pages. For table captions on following pages, it will append *"continued"* to the caption to differentiate. If you need texts other than *"(continued)"* (for example, other languages), you can specify it using `kable_styling(..., repeat_header_text = "xxx")`.
+```{r}
+long_dt <- rbind(mtcars, mtcars)
+
+kable(long_dt, longtable = T, booktabs = T, caption = "Longtable") %>%
+ add_header_above(c(" ", "Group 1" = 5, "Group 2" = 6)) %>%
+ kable_styling(latex_options = c("repeat_header"))
+```
diff --git a/docs/awesome_table_in_pdf.pdf b/docs/awesome_table_in_pdf.pdf
index 8dce25f..d812066 100644
--- a/docs/awesome_table_in_pdf.pdf
+++ b/docs/awesome_table_in_pdf.pdf
Binary files differ