My goal is to create latextable with multirow/multicolumn features from R. The latextable I want should look like this:
colLabel | colLabel2
Consider the kableExtra package.
\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage[table]{xcolor}
\begin{document}
<>=
library(knitr)
opts_chunk$set(echo=FALSE)
library(kableExtra)
options(knitr.table.format = "latex")
dat <- data.frame(
group = c("rowLabel1", "rowLabel1", "rowLabel2", "rowLabel2"),
a1 = c(1, 3, 9, 11),
a2 = c(2, 4, 10, 12),
a3 = c(5, 7, 13, 15),
a4 = c(6, 8, 14, 16)
)
@
<>=
kable(dat, booktabs = TRUE, caption = "My table", escape = FALSE) %>%
add_header_above(c(" ", "colLabel1"=2, "colLabel2"=2)) %>%
kable_styling(latex_options = "hold_position") %>%
column_spec(1, bold=TRUE) %>%
collapse_rows(columns = 1)
@
\end{document}