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

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

    For the most common cases.

    There are 3 conditions.

    1. Everything in portrait mode.
    2. Everything in landscape mode.
    3. Mixture of portrait and landscape modes.

    Let’s narrow down to each conditions.

    1. The first one, say we have a markdown document start with the code below. And this is the default setting in Rstudio when you create an rmd file. When you knit it. It will automatically assume it’s a portrait mode without doubt.

      title: "Landscape and Portrait"
          author: "Jung-Han Wang"
          date: "Thursday, March 19, 2015"
          output: pdf_document
      
    2. When you want to knit the PDF file to landscape mode, the only thing you need to add is classoption: landscape

          title: "Landscape and Portrait"
          author: "Jung-Han Wang"
          date: "Thursday, March 19, 2015"
          output: pdf_document
          classoption: landscape
      
    3. If you want mixture of both, you will need to add .tex file in YAML. By referencing the link I mentioned above. You can download the .tex code here. http://goo.gl/cptOqg Or just simply copy the code and save it as header.tex Then, to make life easier, put this .tex file along with the rmd file to be knitted. Make sure you did these two things: Copy the tex file and move it along with the rmd file. Change the beginning of rmd to be:

       title: "Landscape and Portrait"
          author: "Jung-Han Wang"
          date: "Thursday, March 19, 2015"
          output:
            pdf_document:
              includes:
                in_header: header.tex
      

    This is the summary after I played with this issue and mostly benefited from baptiste's answer.

    I included some snapshots and examples in my blogger my blogger.

    Hope this helps. Good luck.

提交回复
热议问题