防止 kableExtra 横向表中的分页符

Mic*_*per 6 latex r knitr r-markdown kableextra

如何在 R Markdown(PDF 输出)中绘制横向表而不导致插入分页符?

还有就是功能landscapekableExtra包,但是这会强制插入分页符。

例子:

R Markdown 中表格的正常行为是将浮动以最小化文本的分解。

---
output: pdf_document
---

Some Text

```{r, echo=F, warning=F}
library(kableExtra)
knitr::kable(mtcars, format = "latex", caption = "A table")
```

More Text
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

景观:

---
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
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

alk*_*989 5

你可以使用 LaTeX 包 realboxes 来做你想做的事

---
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
Run Code Online (Sandbox Code Playgroud)

这将生成一个单页 pdf,其中表格以横向显示。这种方法的问题在于它似乎不适用于标题。

在此输入图像描述

编辑您可以使用captionLatex 包添加标题

---
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
Run Code Online (Sandbox Code Playgroud)

这会生成带有标题的横向表格

在此输入图像描述