我在 Rmarkdown 中使用 kable 创建了一个乳胶表,如下所示:
---
output: pdf_document
header-includes:
- \usepackage{xcolor}
---
```{r, message=FALSE, warning=FALSE, echo=FALSE}
library(kableExtra)
library(tidyr)
library(dplyr)
data(iris)
iris %>%
as_tibble %>%
gather(.,key = variable,value = value,-Species) %>%
group_by(Species,variable) %>%
summarise(value=mean(value)) %>%
ungroup %>%
spread(.,key = variable,value = value) %>%
mutate(`Percentage Change`=`Petal.Length`/`Petal.Width`*100) %>%
kable(.,format='latex',
align='c',linesep='',
booktabs=TRUE,escape=FALSE) %>%
add_header_above(.,c(' '=1,'Parts'=4,' '=1),
escape = FALSE) %>%
kable_styling(latex_options = c('striped','HOLD_position','scale_down'))
```
Run Code Online (Sandbox Code Playgroud)
我希望将列标题“物种”和“百分比变化”分别与它们上面的空白区域合并,这样就Species可以放在两个标题行的中间,同时Percentage Change (Petal Length/ Petal Width)可以占据两行,而不是有一个空的上面的行,并防止其他列下面有空行。
不知道是否可以kable更好地修改它,也欢迎乳胶“黑客”建议。
谢谢!