如何在R Markdown(PDF输出)中绘制风景表而又不插入分页符?
kableExtra 包中提供了功能landscape
,但这将强制插入分页符。
示例:
R Markdown中表的正常行为是,它将浮动以最小化文本的分解。
---
output: pdf_document
---
Some Text
```{r, echo=F, warning=F}
library(kableExtra)
knitr::kable(mtcars, format = "latex", caption = "A table")
```
More Text
风景:
---
output: pdf_document
---
Some Text
```{r, echo=F, warning=F}
library(kableExtra)
knitr::kable(mtcars, format = "latex", booktabs = T, caption = "A table") %>%
landscape()
```
More Text
答案 0 :(得分:1)
您可以使用LaTeX软件包实箱来完成所需的操作
---
title: "Mixing portrait and landscape"
output: pdf_document
header-includes:
- \usepackage[graphicx]{realboxes}
- \usepackage{booktabs}
---
Some text
\Rotatebox{90}{
```{r, echo=FALSE, warning=FALSE}
knitr::kable(mtcars, "latex", booktabs = TRUE)
```
}
More text
这将产生一个单页pdf,表格以横向显示。这种方法的问题在于它似乎无法与字幕配合使用。
编辑,您可以使用caption
乳胶包添加标题
---
title: "Mixing portrait and landscape"
output: pdf_document
header-includes:
- \usepackage[graphicx]{realboxes}
- \usepackage{booktabs}
- \usepackage{caption}
---
Some text
\begingroup
\captionsetup{type=table}
\caption{A table}
\Rotatebox{90}{
```{r, echo=FALSE, warning=FALSE}
knitr::kable(mtcars, "latex", booktabs = TRUE)
```
}
\endgroup
More text
这会产生带有标题的横向表格