我正在研究R Markdown文档。我有一个这样的数据框架:
library(tidyverse)
library(xtable)
df <- tibble(a = 1:10, b = 1:10, c = 1:10, d = 1:10, e = 1:10, f =1:10,
g = 1:10, h = 1:10, i = 1:10)
我正在使用xtable包来创建显示表。由于表格太宽,我使用scalebox参数
缩放表格xt <- xtable(df, caption = "Table 1")
print(xt, type = "latex", comment = FALSE,floating = F,
include.rownames = F, scalebox = 0.50)
但是,文档上不显示标题。我该怎么办?
答案 0 :(得分:1)
如果您不仅限于使用xtable
,我建议您切换到knitr::kable
和kableExtra
。
---
output: pdf_document
---
```{r setup, include=FALSE}
library(tidyverse)
library(knitr)
library(kableExtra)
df <- tibble(a = 1:10, b = 1:10, c = 1:10, d = 1:10, e = 1:10, f =1:10,
g = 1:10, h = 1:10, i = 1:10)
```
```{r table, results='asis'}
df %>%
kable("latex", caption = "Table 1", booktabs = TRUE) %>%
kable_styling(latex_options = c("striped", "hold_position"))
```
...可生产
此外,scale_down
还有一个等效的latex_options
选项。但是,正如vignette中所述,它将适合页面宽度,因此如果表格不够宽也会向上扩展。