缩放 kable 表以适合页面宽度 [英] Scale kable table to fit page width
本文介绍了缩放 kable 表以适合页面宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 kable 函数格式化 pdf 表格?因为我的输出表格宽度超过了pdf的宽度.下面是一个例子:
---输出:pdf_document---```{r}df <- cbind(mtcars[1:5,], mtcars[1:5,])knitr::kable(df)``
解决方案
一种选择是使用 kableExtra
包中的 kable_styling
.选项 latex_options="scale_down"
将适合纸张边距内的表格.有关所有格式选项的详细示例,请参阅
How do you format a table in pdf using kable function? Because my output table width exceeds the width of the pdf. Here is an example:
---
output: pdf_document
---
```{r}
df <- cbind(mtcars[1:5,], mtcars[1:5,])
knitr::kable(df)
```
解决方案
One option is to use kable_styling
from the kableExtra
package. The option latex_options="scale_down"
will fit the table within the paper margins. See the vignette for detailed examples on all of the formatting options.
---
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")
```
这篇关于缩放 kable 表以适合页面宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文