#101
diff --git a/R/row_spec.R b/R/row_spec.R
index 5a3c617..ee27be7 100644
--- a/R/row_spec.R
+++ b/R/row_spec.R
@@ -29,6 +29,10 @@
#' @param angle 0-360, degree that the text will rotate.
#' @param extra_css Extra css text to be passed into the cells of the row. Note
#' that it's not for the whole row.
+#' @param hline_after T/F. A replicate of `hline.after` in xtable. It
+#' addes a hline after ther row
+#' @param extra_latex_after Extra LaTeX text to be added after the row. Similar
+#' with `add.to.row` in xtable
#'
#' @examples x <- knitr::kable(head(mtcars), "html")
#' row_spec(x, 1:2, bold = TRUE, italic = TRUE)
@@ -38,7 +42,8 @@
bold = FALSE, italic = FALSE, monospace = FALSE,
underline = FALSE, strikeout = FALSE,
color = NULL, background = NULL, align = NULL,
- font_size = NULL, angle = NULL, extra_css = NULL) {
+ font_size = NULL, angle = NULL, extra_css = NULL,
+ hline_after = FALSE, extra_latex_after = NULL) {
if (!is.numeric(row)) {
stop("row must be numeric. ")
}
@@ -56,7 +61,8 @@
if (kable_format == "latex") {
return(row_spec_latex(kable_input, row, bold, italic, monospace,
underline, strikeout,
- color, background, align, font_size, angle))
+ color, background, align, font_size, angle,
+ hline_after, extra_latex_after))
}
}
@@ -168,7 +174,8 @@
row_spec_latex <- function(kable_input, row, bold, italic, monospace,
underline, strikeout,
- color, background, align, font_size, angle) {
+ color, background, align, font_size, angle,
+ hline_after, extra_latex_after) {
table_info <- magic_mirror(kable_input)
out <- enc2utf8(as.character(kable_input))
@@ -183,8 +190,11 @@
target_row <- table_info$contents[i]
new_row <- latex_new_row_builder(target_row, bold, italic, monospace,
underline, strikeout,
- color, background, align, font_size, angle)
- out <- sub(target_row, new_row, out, perl = T)
+ color, background, align, font_size, angle,
+ hline_after, extra_latex_after)
+ out <- str_replace(out,
+ paste0(target_row, "\\\\\\\\"),
+ new_row)
}
out <- structure(out, format = "latex", class = "knitr_kable")
@@ -194,7 +204,8 @@
latex_new_row_builder <- function(target_row, bold, italic, monospace,
underline, strikeout,
- color, background, align, font_size, angle) {
+ color, background, align, font_size, angle,
+ hline_after, extra_latex_after) {
new_row <- latex_row_cells(target_row)
if (bold) {
new_row <- lapply(new_row, function(x) {
@@ -250,5 +261,14 @@
new_row <- paste0("\\\\rowcolor", latex_color(background), " ", new_row)
}
+ new_row <- paste0(new_row, "\\\\\\\\")
+
+ if (hline_after) {
+ new_row <- paste0(new_row, "\n\\\\hline")
+ }
+ if (!is.null(extra_latex_after)) {
+ new_row <- paste0(new_row, "\n",
+ regex_escape(extra_latex_after, double_backslash = TRUE))
+ }
return(new_row)
}
diff --git a/man/cell_spec.Rd b/man/cell_spec.Rd
index d50b580..bc22976 100644
--- a/man/cell_spec.Rd
+++ b/man/cell_spec.Rd
@@ -6,15 +6,15 @@
\title{Specify Cell/Text format}
\usage{
cell_spec(x, format, bold = FALSE, italic = FALSE, monospace = FALSE,
- color = NULL, background = NULL, align = NULL, font_size = NULL,
- angle = NULL, tooltip = NULL, popover = NULL, link = NULL,
- extra_css = NULL, escape = TRUE, background_as_tile = TRUE,
- latex_background_in_cell = TRUE)
+ underline = FALSE, strikeout = FALSE, color = NULL, background = NULL,
+ align = NULL, font_size = NULL, angle = NULL, tooltip = NULL,
+ popover = NULL, link = NULL, extra_css = NULL, escape = TRUE,
+ background_as_tile = TRUE, latex_background_in_cell = TRUE)
text_spec(x, format, bold = FALSE, italic = FALSE, monospace = FALSE,
- color = NULL, background = NULL, align = NULL, font_size = NULL,
- angle = NULL, tooltip = NULL, popover = NULL, link = NULL,
- escape = TRUE, background_as_tile = TRUE,
+ underline = FALSE, strikeout = FALSE, color = NULL, background = NULL,
+ align = NULL, font_size = NULL, angle = NULL, tooltip = NULL,
+ popover = NULL, link = NULL, escape = TRUE, background_as_tile = TRUE,
latex_background_in_cell = FALSE)
}
\arguments{
@@ -29,6 +29,12 @@
\item{monospace}{T/F for font monospaced (verbatim)}
+\item{underline}{A T/F value to control whether the text of the selected row
+need to be underlined}
+
+\item{strikeout}{A T/F value to control whether the text of the selected row
+need to be stricked out.}
+
\item{color}{A character string for text color. Here please pay
attention to the differences in color codes between HTML and LaTeX.}
diff --git a/man/collapse_rows.Rd b/man/collapse_rows.Rd
index e1078a3..677214a 100644
--- a/man/collapse_rows.Rd
+++ b/man/collapse_rows.Rd
@@ -4,12 +4,16 @@
\alias{collapse_rows}
\title{Collapse repeated rows to multirow cell}
\usage{
-collapse_rows(kable_input, columns = NULL)
+collapse_rows(kable_input, columns = NULL, latex_hline = c("full", "major",
+ "none"))
}
\arguments{
\item{kable_input}{Output of \code{knitr::kable()} with \code{format} specified}
\item{columns}{Numeric column positions where rows need to be collapsed.}
+
+\item{latex_hline}{Option controlling the behavior of adding hlines to table.
+Choose from \code{full}, \code{major}, \code{none}.}
}
\description{
Collapse same values in columns into multirow cells. This
diff --git a/man/column_spec.Rd b/man/column_spec.Rd
index c3f0e35..27f8de2 100644
--- a/man/column_spec.Rd
+++ b/man/column_spec.Rd
@@ -5,7 +5,8 @@
\title{Specify the look of the selected column}
\usage{
column_spec(kable_input, column, width = NULL, bold = FALSE,
- italic = FALSE, monospace = FALSE, color = NULL, background = NULL,
+ italic = FALSE, monospace = FALSE, underline = FALSE,
+ strikeout = FALSE, color = NULL, background = NULL,
border_left = FALSE, border_right = FALSE, extra_css = NULL)
}
\arguments{
@@ -25,6 +26,12 @@
\item{monospace}{A T/F value to control whether the text of the selected column
need to be monospaced (verbatim)}
+\item{underline}{A T/F value to control whether the text of the selected row
+need to be underlined}
+
+\item{strikeout}{A T/F value to control whether the text of the selected row
+need to be stricked out.}
+
\item{color}{A character string for column text color. Here please pay
attention to the differences in color codes between HTML and LaTeX.}
diff --git a/man/row_spec.Rd b/man/row_spec.Rd
index da3c7b2..f803a7b 100644
--- a/man/row_spec.Rd
+++ b/man/row_spec.Rd
@@ -5,8 +5,9 @@
\title{Specify the look of the selected row}
\usage{
row_spec(kable_input, row, bold = FALSE, italic = FALSE,
- monospace = FALSE, color = NULL, background = NULL, align = NULL,
- font_size = NULL, angle = NULL, extra_css = NULL)
+ monospace = FALSE, underline = FALSE, strikeout = FALSE, color = NULL,
+ background = NULL, align = NULL, font_size = NULL, angle = NULL,
+ extra_css = NULL, hline_after = FALSE, extra_latex_after = NULL)
}
\arguments{
\item{kable_input}{Output of \code{knitr::kable()} with \code{format} specified}
@@ -20,9 +21,15 @@
\item{italic}{A T/F value to control whether the text of the selected row
need to be emphasized.}
-\item{monospace}{A T/F value to control whether the text of the selected column
+\item{monospace}{A T/F value to control whether the text of the selected row
need to be monospaced (verbatim)}
+\item{underline}{A T/F value to control whether the text of the selected row
+need to be underlined}
+
+\item{strikeout}{A T/F value to control whether the text of the selected row
+need to be stricked out.}
+
\item{color}{A character string for row text color. For example, "red" or
"#BBBBBB".}
@@ -41,6 +48,12 @@
\item{extra_css}{Extra css text to be passed into the cells of the row. Note
that it's not for the whole row.}
+
+\item{hline_after}{T/F. A replicate of \code{hline.after} in xtable. It
+addes a hline after ther row}
+
+\item{extra_latex_after}{Extra LaTeX text to be added after the row. Similar
+with \code{add.to.row} in xtable}
}
\description{
This function allows users to select a row and then specify
diff --git a/tests/visual_tests/column_row_spec_pdf.Rmd b/tests/visual_tests/column_row_spec_pdf.Rmd
index e8fef90..2e1acb0 100644
--- a/tests/visual_tests/column_row_spec_pdf.Rmd
+++ b/tests/visual_tests/column_row_spec_pdf.Rmd
@@ -47,3 +47,9 @@
row_spec(3, monospace = T, color = "yellow", background = "black")
```
+```{r}
+kable(mtcars[1:5, 1:5], "latex", booktabs = T) %>%
+ row_spec(2, extra_latex_after = "\\cline{2-6}") %>%
+ row_spec(4, hline_after = T)
+```
+