I'm creating APA style tables using r markdown, latex and the package papaja with the function apa_table()
for pdf documents. I would like to add an additional named col_spanner on top of the existing ones (two, with names 'Cars 1' and 'Cars 2', see picture), spanning from column 2 up to and including column 9 with the name or header 'Cars'.
With kableExtra() this is not a problem, you would just add: add_header_above(c(" ", "Cars" = 8))
. But this doesn't work with papaja, latex and pdf files (as far as i could figure out).
Code and picture included to illustrate.
{r , results= 'asis'}
library(papaja)
my_table <- t(apply(cars, 2, function(x) {
round(c(Mean = mean(x), SD = sd(x), Min = min(x), Max = max(x)), 2)
}))
apa_table(cbind(my_table, my_table),
align = c("l", rep("r", 8)),
caption = "A summary table of the cars dataset.",
note = "This table was created using apa\\_table()",
added_stub_head = "Variables",
col_spanners = list(`Cars 1` = c(2, 5), `Cars 2` = c(6, 9)))