Search code examples
pdflatexlandscapequarto

Create a multiple page orientation in a single quarto PDF output


The idea is to replicate the PDF output on rmarkdown in quarto, in this case, is creating a multiple-page orientation on a single document. In rmarkdown I can do it easily by using this trick. However, I could not do that in quarto, it keeps sending the error message

compilation failed- error 
Undefined control sequence.
l.201 \blandscape

Here is my code:

---
title: "Portrait and Landscape"
format:
  pdf:
    include-in-header:
      - packages.tex
---

# Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

\newpage
\blandscape

# Running Code

When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

You can add options to executable code like this 

The `echo: false` option disables the printing of code (only output is displayed).

\elandscape

Interestingly, I can create a multiple page orientation by modified the YAML and inserting raw latex to start and end the landscape page, but it will erase all the rmarkdown formatting and turned it into normal text inside the landscape page:

---
title: "Portrait and Landscape"
format: 
  pdf:
    include-in-header:
        text: |
           \usepackage{pdflscape}
---


\begin{landscape}

bla bla bla

\end{landscape}


Is there any workaround on this matter?

PS: my header.tex contains this stuff

\usepackage{pdflscape}
    \newcommand{\blandscape}{\begin{landscape}}
    \newcommand{\elandscape}{\end{landscape}}

Solution

  • Option 01

    You can use lscape LaTeX package. This rotates the page contents but not the page number.

    ---
    title: "Portrait and Landscape"
    format:
      pdf:
        include-in-header: 
          text: |
            \usepackage{lscape}
            \newcommand{\blandscape}{\begin{landscape}}
            \newcommand{\elandscape}{\end{landscape}}
    ---
    
    # Quarto
    
    Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
    
    \newpage
    
    \blandscape
    
    # Running Code
    
    When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
    
    You can add options to executable code like this 
    
    The `echo: false` option disables the printing of code (only output is displayed).
    
    \elandscape
    
    

    Option 02

    You can also use typearea package of KOMA-Script to do this. To my understanding, It not just changes the page contents orientation, but also sets the pdf page rotation attribute in such a way that pages with this attribute will be displayed in landscape orientation when viewing with PDF viewers. And also preserves the page number position.

    ---
    title: "Portrait and Landscape"
    format:
      pdf:
        include-in-header: 
          text: |
            \usepackage{typearea}
    ---
    
    # Quarto
    
    
    Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
    
    \newpage
    
    <!-- changing the orientation to landscape --------------------------------- -->
    
    \KOMAoptions{paper=landscape,pagesize}
    \recalctypearea
    
    # Running Code (Landscape)
    
    When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
    
    You can add options to executable code like this 
    
    The `echo: false` option disables the printing of code (only output is displayed).
    
    \newpage
    
    <!-- % changing the orientation to portrait again -------------------------- -->
    
    \KOMAoptions{paper=portrait,pagesize}
    \recalctypearea
    
    # Quarto (Portrait)
    
    Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.