Rstudio rmarkdown: both portrait and landscape layout in a single PDF

后端 未结 4 1547
孤城傲影
孤城傲影 2020-11-27 10:26

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

4条回答
  •  暖寄归人
    2020-11-27 10:54

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

提交回复
热议问题