防止kableExtra景观表中的分页符 [英] Prevent pagebreak in kableExtra landscape table
问题描述
如何在不插入分页符的情况下在R Markdown(PDF输出)中绘制风景表?
How can a landscape table be plotted in R Markdown (PDF output) without causing a page break to be inserted?
kableExtra 包中提供了功能landscape
,但这将强制插入分页符.
There is the function landscape
from the kableExtra package, but this forces a page break to be inserted.
示例:
R Markdown中表的正常行为是会浮动以最大程度地减少文本的拆分.
The normal behaviour for tables in R Markdown is that the will float to minimise the breaking up of text.
---
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
推荐答案
您可以使用LaTeX包realboxes进行所需的操作
You can use the LaTeX package realboxes to do what you want
---
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,表格以横向显示.这种方法的问题在于它似乎无法与字幕配合使用.
This produces a single page pdf with the table presented in landscape. The problem with this approach is that it does not seem to work with a caption.
编辑,您可以使用caption
乳胶包添加标题
Edit You can use the caption
latex package to add the 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
这会产生带有标题的横向表格
This produces the table in landscape with caption
这篇关于防止kableExtra景观表中的分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!