请参见下面的rmd文件。我想倾斜一些列标题并注意宽度。
在没有row_spec()的第一个表中,将考虑宽度,但是当将row_spec()添加到一定角度时,一些列标题的宽度将不再成立。知道如何调整角度并保持宽度吗?
rmd文件
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)
```
```{r table1, echo= FALSE, comment = FALSE, message= FALSE, warning = FALSE,results='asis'}
dt <- mtcars[1:5, 1:6]
rownames(dt) = NULL
colnames(dt)= c("long col 1","long col 12","long col 13","long col 14","long col 15","long col 16")
kable(
dt,
format ="latex",
caption = "No angle",
booktabs = T,
longtable = T,
escape = F,
align = "c",
linesep=""
) %>%
kable_styling(latex_options = c("repeat_header" ), font_size=8)%>%
collapse_rows(columns = 1, latex_hline = "major", valign = "middle") %>%
column_spec(c(1,2,3,4,5,6), width = c("8em","5em","6em","3em","3em","3em" ) )
```
```{r table2, echo= FALSE, comment = FALSE, message= FALSE, warning = FALSE,results='asis'}
kable(
dt,
format ="latex",
caption = "With Angled columns",
booktabs = T,
longtable = T,
escape = F,
align = "c",
linesep=""
) %>%
kable_styling(latex_options = c("repeat_header" ), font_size=8)%>%
collapse_rows(columns = 1, latex_hline = "major", valign = "middle") %>%
row_spec(0, angle = c(rep(0,2),rep(90,2),rep(0,2) ) )%>%
column_spec(c(1,2,3,4,5,6), width = c("8em","5em","6em","3em","3em","3em" ) )
```