added add_indent_latex
diff --git a/NAMESPACE b/NAMESPACE
index a431fba..8d5aace 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -3,6 +3,7 @@
export("%>%")
export(add_footnote)
export(add_header_above)
+export(add_indent)
export(kable_styling)
export(landscape)
export(magic_mirror)
diff --git a/R/add_indent.R b/R/add_indent.R
new file mode 100644
index 0000000..c88b33d
--- /dev/null
+++ b/R/add_indent.R
@@ -0,0 +1,41 @@
+#' Add indentations to row headers
+#' @export
+add_indent <- function(kable_input, positions) {
+ kable_format <- attr(kable_input, "format")
+ if (!kable_format %in% c("html", "latex")) {
+ message("Currently generic markdown table using pandoc is not supported.")
+ return(kable_input)
+ }
+ if (kable_format == "html") {
+ return(kable_input)
+ }
+ if (kable_format == "latex") {
+ return(add_indent_latex(kable_input, positions))
+ }
+}
+
+add_indent_latex <- function(kable_input, positions) {
+ table_info <- attr(kable_input, "original_kable_meta")
+ if (is.null(table_info)) {
+ table_info <- magic_mirror(kable_input)
+ }
+
+ if (!is.numeric(positions)) {
+ stop("Positions can only take numeric row numbers (excluding header rows).")
+ }
+ if (max(positions) > table_info$nrow - 1) {
+ stop("There aren't that many rows in the table. Check positions in ",
+ "add_indent_latex.")
+ }
+
+ out <- kable_input
+ for (i in positions) {
+ rowtext <- table_info$contents[i + 1]
+ out <- sub(rowtext, latex_indent_unit(rowtext), out)
+ }
+ return(out)
+}
+
+latex_indent_unit <- function(rowtext) {
+ paste0("\\\\hspace{1em}", rowtext)
+}
diff --git a/R/landscape.R b/R/landscape.R
index 6f4049c..5727fe6 100644
--- a/R/landscape.R
+++ b/R/landscape.R
@@ -1,9 +1,7 @@
#' Print the table on an isolated landscape page in PDF
#'
-#' @description For very wide tables in PDF documents, sometimes it might be a
-#' good idea to have a single landscape page to house it. This function
-#' will rotate the PDF page for the applied table in LaTeX environment. It won't
-#' have any effects on HTML.
+#' @description This function will put the table on an single landscape page.
+#' It's useful for wide tables that cann't be printed on a portrait page.
#'
#' @param kable_input Output of `knitr::kable()` with `format` specified
#' @param margin Customizable page margin for special needs. Values can be
diff --git a/man/add_indent.Rd b/man/add_indent.Rd
new file mode 100644
index 0000000..43fad6d
--- /dev/null
+++ b/man/add_indent.Rd
@@ -0,0 +1,11 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/add_indent.R
+\name{add_indent}
+\alias{add_indent}
+\title{Add indentations to row headers}
+\usage{
+add_indent(kable_input, positions)
+}
+\description{
+Add indentations to row headers
+}
diff --git a/man/landscape.Rd b/man/landscape.Rd
index 2048727..48bc501 100644
--- a/man/landscape.Rd
+++ b/man/landscape.Rd
@@ -13,8 +13,6 @@
"1cm", "1in" or similar.}
}
\description{
-For very wide tables in PDF documents, sometimes it might be a
-good idea to have a single landscape page to house it. This function
-will rotate the PDF page for the applied table in LaTeX environment. It won't
-have any effects on HTML.
+This function will put the table on an single landscape page.
+It's useful for wide tables that cann't be printed on a portrait page.
}
diff --git a/tests/visual_tests/indent_and_row_group.Rmd b/tests/visual_tests/indent_and_row_group.Rmd
new file mode 100644
index 0000000..4ad0262
--- /dev/null
+++ b/tests/visual_tests/indent_and_row_group.Rmd
@@ -0,0 +1,20 @@
+---
+title: "indents & row_group"
+output: pdf_document
+---
+
+# Introduction
+Nam non libero ut felis euismod efficitur. Maecenas ligula nisi, rutrum eu turpis quis, semper ultricies nibh. Quisque vehicula cursus erat. Donec aliquam augue ut magna vehicula lacinia. Quisque efficitur, arcu condimentum mollis scelerisque, tellus libero accumsan elit, in eleifend lorem lectus ut erat. Ut sit amet nulla quis turpis semper mattis. Ut rhoncus vitae nulla sit amet ultrices. Nulla justo ligula, rhoncus et interdum vel, cursus ut sem. Nullam elementum ullamcorper neque, imperdiet tempus sapien tincidunt et. Nulla diam nulla, varius ut nisi quis, hendrerit fringilla mi. In volutpat tincidunt faucibus. Donec luctus, mauris vitae consectetur placerat, elit velit tristique mauris, sed malesuada nisl sem eu justo. Nunc enim quam, pharetra vitae velit vel, posuere lacinia turpis. Proin volutpat porttitor ligula.
+
+```{r}
+library(knitr)
+library(kableExtra)
+dt <- mtcars[1:5, 1:8]
+```
+
+```{r}
+kable(dt, format = "latex", booktabs = T) %>%
+ kable_styling(latex_options = c("striped", "hold_position")) %>%
+ add_indent(c(3, 5)) %>%
+ add_indent(5)
+```