中的纵向和横向布局

中的纵向和横向布局

本文介绍了Rstudio rmarkdown:单个 PDF 中的纵向和横向布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 rmarkdown 生成在同一文档中同时具有纵向和横向布局的 pdf.如果有一个纯 rmarkdown 选项会比使用乳胶更好.

I wonder how to use rmarkdown to generate a pdf which has both portrait and landscape layout in the same document. If there is a pure rmarkdown option that would be even better than using latex.

这是一个可重现的小示例.首先,在 RStudio 中渲染此 .Rmd(按 Knit PDF 按钮)会生成一个 pdf,其中所有页面均采用横向布局:

Here's a small, reproducible example. First, rendering this .Rmd in RStudio (press Knit PDF button) results in a pdf with all pages in landscape layout:

---
title: "All pages landscape"
output: pdf_document
classoption: landscape
---

```{r}
summary(cars)
```


ewpage
```{r}
summary(cars)
```

然后尝试创建一个混合纵向和横向布局的文档.YAML 中的基本设置是根据此处的包含"部分完成的.in_header 文件 'header.tex' 只包含 usepackage{lscape},一个推荐用于 knitr 横向布局的包 这里..tex 文件与 .Rmd 文件位于同一目录中.

Then an attempt to create a document which mixes portrait and landscape layout. The basic setup in the YAML is done according to the 'Includes' section here. The in_header file 'header.tex' only contains usepackage{lscape}, a package suggested for knitr landscape layout here. The .tex file is in the same directory as the .Rmd file.

---
title: "Mixing portrait and landscape"
output:
    pdf_document:
        includes:
            in_header: header.tex
---

Portrait:
```{r}
summary(cars)
```


ewpage
egin{landscape}
Landscape:
```{r}
summary(cars)
```
end{landscape}


ewpage
More portrait:
```{r}
summary(cars)
```

但是,此代码导致错误:

However, this code results in an error:

# ! You can't use `macro parameter character #' in horizontal mode.
# l.116 #

# pandoc.exe: Error producing PDF from TeX source
# Error: pandoc document conversion failed with error 43

非常感谢任何帮助.

推荐答案

所以,pandoc 解析乳胶环境的内容,但你可以通过重新定义header.tex 文件中的命令:

So, pandoc does not parse the content of latex environments, but you can fool it by redefining the commands in your header.tex file:

usepackage{lscape}

ewcommand{landscape}{egin{landscape}}

ewcommand{elandscape}{end{landscape}}

因此,这里的 egin{landscape} 被重新定义为 landscape,而 end{landscape} 被重新定义为 elandscape.在 .Rmd 文件中使用那些新定义的命令似乎有效:

Thus, here egin{landscape} is redefined to landscape, and end{landscape} to elandscape. Using those newly defined command in the .Rmd file seems to work:

---
title: "Mixing portrait and landscape"
output:
    pdf_document:
        includes:
            in_header: header.tex
---

Portrait
```{r}
summary(cars)
```


ewpage
landscape
Landscape
```{r}
summary(cars)
```
elandscape


ewpage
More portrait
```{r}
summary(cars)
```

这篇关于Rstudio rmarkdown:单个 PDF 中的纵向和横向布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:38