I'm trying to generate a nice table using Rmarkdown to export in pdf, to do so I'm using kable
and its formatting options and the function collpase_rows
to merge some cells.Here it's the problem, I'm using the argument valign="middle"
but it's not correctly aligning to the middle of the space, "Example1" should be aligned with the number "2" in the second column and it's not.
Do you have any idea how to properly align the collapsed cells?
This is the code I'm using to generate the table:
library(kableExtra)library(tidyr)library(dplyr)data <- data.frame(A=c(rep("Example1",3),rep("Example2",3)),B=1:6,C=c(1,1,1,2,2,2),D=6:1,E=c(1,1,1,2,2,2))knitr::kable(data, col.names = linebreak(c("","B","C","B", "C"),align = 'c'), caption = "Example.", format = "latex", booktabs = T, linesep="\\addlinespace", escape = F, align = "c") %>% add_header_above(.,c(''=1,'Ascending'=2,'Descending'=2), bold = T, escape = F) %>% collapse_rows(columns = c(1,3,5), valign = "middle") %>% kable_styling(font_size = 10, latex_options = c("striped", "hold_position"))