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 opt
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}
\newcommand{\blandscape}{\begin{landscape}}
\newcommand{\elandscape}{\end{landscape}}
Thus, here \begin{landscape} is redefined to \blandscape, 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)
```
\newpage
\blandscape
Landscape
```{r}
summary(cars)
```
\elandscape
\newpage
More portrait
```{r}
summary(cars)
```