PDF 和 Word 输出中具有弹性表的横向表格

问题描述 投票:0回答:1

我正在使用

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 r-markdown landscape bookdown flextable
1个回答
0
投票

R markdown stmt 中的一些问题:


标题包括:

  • \usepackage{pdflscape} 输出: 书本::pdf_document2: number_sections:假 Latex_引擎:xelatex 书本::word_document2: number_sections:假 总是_allow_html:真 几何形状:“左=2.5cm,右=2cm,上=2cm,下=2cm” 字体大小:12pt 线拉伸:1.5

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.
© www.soinside.com 2019 - 2024. All rights reserved.