防止kableExtra横向表格中的分页符

时间:2018-08-01 12:33:53

标签: r latex r-markdown knitr kableextra

如何在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

enter image description here

风景

---
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

enter image description here

1 个答案:

答案 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,表格以横向显示。这种方法的问题在于它似乎无法与字幕配合使用。

enter image description here

编辑,您可以使用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

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

enter image description here