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

后端 未结 4 1545
孤城傲影
孤城傲影 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:29

    Building upon previous solutions, the following solution does not require an auxiliary header.tex file. All contents are contained in the .Rmd file. The LaTeX commands are instead defined in a header-includes block in the YAML header. More info can be found here.

    Also, I noticed that using the lscape LaTeX package rotates the contents of a page, but not the PDF page itself. This is resolved using the pdflscape package.

    ---
    title: "Mixing portrait and landscape WITHOUT a header.tex file"
    header-includes:
    - \usepackage{pdflscape}
    - \newcommand{\blandscape}{\begin{landscape}}
    - \newcommand{\elandscape}{\end{landscape}}
    output: pdf_document
    ---
    
    Portrait
    ```{r}
    summary(cars)
    ```
    
    \newpage
    \blandscape
    Landscape
    ```{r}
    summary(cars)
    ```
    \elandscape
    
    \newpage
    More portrait
    ```{r}
    summary(cars)
    ```
    

提交回复
热议问题