我正在使用
bookdown
将文档从 rmarkdown 编织为 pdf 和 .docx。我有一些表格想放在横向页面上。我用 flextable
制作了表格,因为我需要为我的主管提供 Word 文档版本,但最终,我想将其编织成 pdf,因为我的其他一些部分有 kable
项目和其他我没有的功能不想改变。对于 kable
表,我可以只使用 kableExtra::landscape()
。有没有简单版的flextable
?
目前,我将
\landscape
和 \endlandscape
放置在所有需要横向的表格的代码块的两侧,以生成 pdf,但这并不理想。
MWE:
header-includes:
- \usepackage{pdflscape}
output:
bookdown::pdf_document2:
number_sections: false
latex_engine: xelatex
bookdown::word_document2:
number_sections: false
always_allow_html: true
geometry: "left=2.5cm,right=2cm,top=2cm,bottom=2cm"
fontsize: 12pt
linestretch: 1.5
---
```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(echo = FALSE, warning = F, message = F)
library(dplyr)
library(flextable)
library(ftExtra)
```
Some text on portrait page
\landscape
```{r table}
flextable(mtcars)%>%
autofit()%>%
theme_booktabs(bold_header = T)%>%
set_caption("Table caption")%>%
fontsize(size = 11, part = "all")
```
\endlandscape
More text, next line back to portrait
我正在使用命令渲染:
bookdown::render_book(".", "bookdown::word_document2", config_file = "_bookdown.yml", preview = F, clean = T)
bookdown::render_book(".", "bookdown::pdf_document2", config_file = "_bookdown.yml", preview = F, clean = T)
R markdown stmt 中的一些问题:
标题包括:
library(knitr)
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(dplyr)
library(flextable)
library(ftExtra)
begin:
flextable(mtcars) %>%
autofit() %>%
theme_booktabs(bold_header = TRUE) %>%
set_caption("Table caption") %>%
fontsize(size = 11, part = "all")
end:
This modification uses the LaTeX `landscape` environment directly in your R Markdown document. The tables within this environment will be rendered in landscape mode.
Now, when you knit the document to a PDF using `bookdown::render_book`, the table within the `landscape` environment will be displayed in landscape orientation.
Remember to adjust the YAML metadata and R code chunk options according to your specific requirements.