Adding a latex_wrap_text option to pack_rows (#376)
diff --git a/R/group_rows.R b/R/group_rows.R
index e913497..c7d5178 100644
--- a/R/group_rows.R
+++ b/R/group_rows.R
@@ -23,6 +23,9 @@
#' centered on row, "r" for right justification, or "l" for left justification. Default
#' Value is "l" If using html, the alignment can be set by using the label_row_css
#' parameter.
+#' @param latex_wrap_text T/F for wrapping long text. Default is off. Whenever
+#' it is turned on, the table will take up the entire line. It's recommended
+#' to use this with full_width in kable_styling.
#' @param colnum A numeric that determines how many columns the text should span.
#' The default setting will have the text span the entire length.
#' @param bold A T/F value to control whether the text should be bolded.
@@ -44,7 +47,9 @@
index = NULL,
label_row_css = "border-bottom: 1px solid;",
latex_gap_space = "0.3em",
- escape = TRUE, latex_align = "l", colnum = NULL,
+ escape = TRUE, latex_align = "l",
+ latex_wrap_text = FALSE,
+ colnum = NULL,
bold = TRUE,
italic = FALSE,
hline_before = FALSE,
@@ -61,7 +66,7 @@
}
if (is.null(index)) {
if (kable_format == "html") {
- if(!missing(latex_align)) warning("latex_align parameter is not used in HTML Mode,
+ if (!missing(latex_align)) warning("latex_align parameter is not used in HTML Mode,
use label_row_css instead.")
return(group_rows_html(kable_input, group_label, start_row, end_row,
label_row_css, escape, colnum, indent))
@@ -70,14 +75,14 @@
return(group_rows_latex(kable_input, group_label, start_row, end_row,
latex_gap_space, escape, latex_align, colnum,
bold, italic, hline_before, hline_after,
- extra_latex_after, indent))
+ extra_latex_after, indent, latex_wrap_text))
}
} else {
index <- group_row_index_translator(index)
out <- kable_input
if (kable_format == "html") {
for (i in 1:nrow(index)) {
- if(!missing(latex_align)) warning("latex_align parameter is not used in HTML Mode,
+ if (!missing(latex_align)) warning("latex_align parameter is not used in HTML Mode,
use label_row_css instead.")
out <- group_rows_html(out, index$header[i],
index$start[i], index$end[i],
@@ -90,7 +95,7 @@
index$start[i], index$end[i],
latex_gap_space, escape, latex_align, colnum,
bold, italic, hline_before, hline_after,
- extra_latex_after, indent)
+ extra_latex_after, indent, latex_wrap_text)
}
}
return(out)
@@ -148,8 +153,8 @@
group_rows_latex <- function(kable_input, group_label, start_row, end_row,
gap_space, escape, latex_align, colnum,
- bold = T, italic = F, hline_before = F ,hline_after = F,
- extra_latex_after = NULL, indent) {
+ bold = T, italic = F, hline_before = F, hline_after = F,
+ extra_latex_after = NULL, indent, latex_wrap_text = F) {
table_info <- magic_mirror(kable_input)
out <- solve_enc(kable_input)
@@ -166,8 +171,19 @@
if (bold) {
group_label <- paste0("\\\\textbf{", group_label, "}")
}
+
if (italic) group_label <- paste0("\\\\textit{", group_label, "}")
# Add group label
+ if (latex_wrap_text) {
+ latex_align <- switch(
+ latex_align,
+ "l" = "p{\\\\linewidth}",
+ "c" = ">{\\\\centering\\\\arraybackslash}p{\\\\linewidth}",
+ "r" = ">{\\\\centering\\\\arraybackslash}p{\\\\linewidth}"
+ )
+ }
+
+
if (table_info$booktabs) {
rowtext <- table_info$contents[start_row + table_info$position_offset]
pre_rowtext <- paste0(