2

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}}
shafee
  • 15,566
  • 3
  • 19
  • 47

1 Answers1

8

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>.

shafee
  • 15,566
  • 3
  • 19
  • 47
  • Well... it also worked for me, but came out with a warning `Error in yaml::yaml.load(..., eval.expr = TRUE) : Scanner error: mapping values are not allowed in this context at line 3, column 20` Is it okay? I will consider it as an answer for now... Thanks! – Bram Setyadji Madusuyatno Oct 28 '22 at 12:44
  • Well I am completely lost with this error message? Did you run this answer as a separate quarto document and got this error? – shafee Oct 28 '22 at 13:05
  • No... I copied your code and run it as it is. It managed to create the PDF but there was some error warning followed. – Bram Setyadji Madusuyatno Oct 28 '22 at 23:18
  • I would suggest to look carefully at the yaml header or write that yaml header instead of copy paste. What about the second option?! – shafee Oct 29 '22 at 02:58
  • 1
    The second option works like a charm!!! – Bram Setyadji Madusuyatno Oct 29 '22 at 08:25
  • The second option works exactly like I want it to be, except my `geometry`-settings aren't respected on the landscape pages. Any ideas how 1) use the geometry settings from my header or 2) set the geometry for the landscape pages? – andreas Feb 14 '23 at 13:22
  • I've posted a separate question including a repex: https://stackoverflow.com/questions/75448582/use-geometry-on-landscape-pages-when-creating-multiple-page-orientation-in-a-s – andreas Feb 14 '23 at 13:34