allow users to choice full-midline or not
diff --git a/R/add_header_left.R b/R/add_header_left.R
index 6fa6971..97336e5 100644
--- a/R/add_header_left.R
+++ b/R/add_header_left.R
@@ -4,7 +4,7 @@
#'
#' @export
add_header_left <- function(kable_input, header = NULL, header_name = "",
- align = "c") {
+ align = "c", ...) {
if (is.null(header)) return(kable_input)
kable_format <- attr(kable_input, "format")
if (!kable_format %in% c("html", "latex")) {
@@ -15,7 +15,7 @@
return(add_header_left_html(kable_input, header, header_name, align))
}
if (kable_format == "latex") {
- return(add_header_left_latex(kable_input, header, header_name, align))
+ return(add_header_left_latex(kable_input, header, header_name, align, ...))
}
}
@@ -74,7 +74,8 @@
))
}
-add_header_left_latex <- function(kable_input, header, header_name, align) {
+add_header_left_latex <- function(kable_input, header, header_name, align,
+ full_midline = F) {
table_info <- magic_mirror(kable_input)
usepackage_latex("multirow")
if (!table_info$booktabs) {
@@ -95,6 +96,7 @@
paste0(table_info$begin_tabular, "{", align,
ifelse(table_info$booktabs, "", "|")),
out, perl = T)
+ table_info$align_vector <- c(align, table_info$align_vector)
# Header
if (!is.null(table_info$new_header_row)) {
@@ -146,7 +148,9 @@
out <- sub(
paste0(contents[header$row_end[j]], "\\\\\\\\\n"),
paste0(contents[header$row_end[j]],
- "\\\\\\\\\n\\\\cmidrule[0.5pt](l{2pt}r{2pt}){1-1}\n"),
+ "\\\\\\\\\n\\\\cmidrule[0.5pt](l{2pt}r{2pt}){1-",
+ ifelse(full_midline, str_count(tbody[1], " & ") + 2, 1),
+ "}\n"),
out
)
}
diff --git a/docs/awesome_table_in_pdf.Rmd b/docs/awesome_table_in_pdf.Rmd
index c20f16f..d05733e 100644
--- a/docs/awesome_table_in_pdf.Rmd
+++ b/docs/awesome_table_in_pdf.Rmd
@@ -253,12 +253,14 @@
```
# Add header column to the left
-An alternative way of grouping rows is being added to `kableExtra` 0.3.0. Unlike `group_rows`, the new function `add_header_left` adopts a similar syntax with `add_header_above`. It allows users to add multiple layers of row groups, which is a limitation of `group_rows`. A limitation of `add_header_left` is that, you can only use it in `booktabs` tables. There is no future plan to extend support to LaTeX table without booktabs because when a new layer of heading columns being added, every `cline` in normal table needs to be changed. Other limitations include incompatible with `group_rows` and a little in-stable `striped` row coloring behavior. If you don't have special need for multiple layers of heading columns or special love to this format, I will recommend you stick with `group_rows`.
+An alternative way of grouping rows is being added to `kableExtra` 0.3.0. Unlike `group_rows`, the new function `add_header_left` adopts a similar syntax with `add_header_above`. It allows users to add multiple layers of row groups, which is a limitation of `group_rows`. One limitation of `add_header_left` is that, you can only use it in `booktabs` tables. There is no future plan to extend support to LaTeX table without booktabs because it is techinically very difficult. Other limitations include incompatible with `group_rows` and a little in-stable `striped` row coloring behavior. If you don't have special need for multiple layers of heading columns or special love to this format, I will recommend you stick with `group_rows`.
```{r}
mtcars[1:10, 1:6] %>%
kable("latex", booktabs= T) %>%
add_header_above(c(" ", "Data 1" = 3, "Data 2" = 3)) %>%
- add_header_left(c("Group A" = 3, "Group B" = 7), "Group") %>%
- add_header_left(c("Team X" = 4, "Team Y" = 2, "Team Z" = 4), "Team")
+ add_header_left(c("Group A" = 3, "Group B" = 2, "Group C" = 4, "Group D" = 1), "Group") %>%
+ add_header_left(c("Team X" = 5, "Team Y" = 5), "Team", full_midline = T) %>%
+ add_header_left(c("League Alpha" = 10), "League") %>%
+ column_spec(1, bold = T)
```
diff --git a/docs/awesome_table_in_pdf.pdf b/docs/awesome_table_in_pdf.pdf
index 0f92239..edebef7 100644
--- a/docs/awesome_table_in_pdf.pdf
+++ b/docs/awesome_table_in_pdf.pdf
Binary files differ