如何使用 kable 函数格式化 pdf 中的表格?因为我的输出表格宽度超过了pdf的宽度。这是一个例子:
---
output: pdf_document
---
```{r}
df <- cbind(mtcars[1:5,], mtcars[1:5,])
knitr::kable(df)
```
一种选择是使用kable_styling
来自kableExtra
包裹。选项latex_options="scale_down"
将使表格适合纸张边距。看小插图 https://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf有关所有格式选项的详细示例。
---
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(kableExtra)
```
```{r}
kable(cbind(mtcars[1:5,], mtcars[1:5,]))
```
```{r}
kable(cbind(mtcars[1:5,], mtcars[1:5,]), format="latex", booktabs=TRUE) %>%
kable_styling(latex_options="scale_down")
```
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)