Create a multiple page orientation in a single quarto PDF output
Asked Answered
V

1

5

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}}
Vanpelt answered 28/10, 2022 at 1:36 Comment(4)
Whats the content of your packages.tex?Compony
I have updated the packaged.tex contents in my question, thank you for pointing that out.Vanpelt
lscape or pdflscape which one do you need to use?Compony
I prefer pdflscape, but anything that work is OK. I've tried both in quarto but had no luck.Vanpelt
C
13

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

Compony answered 28/10, 2022 at 12:36 Comment(9)
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!Vanpelt
Well I am completely lost with this error message? Did you run this answer as a separate quarto document and got this error?Compony
No... I copied your code and run it as it is. It managed to create the PDF but there was some error warning followed.Vanpelt
I would suggest to look carefully at the yaml header or write that yaml header instead of copy paste. What about the second option?!Compony
The second option works like a charm!!!Vanpelt
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?Sphene
I've posted a separate question including a repex: #75449082Sphene
@shafee when I try option 2 I get the error message render fail due to invalid YAML. I'm typing this (see below) in my YAML. What am I missing? format: pdf: default include-in-header: text: \usepackage{typearea}Outdo
@ianaj, remove that default after the option pdf.Compony

© 2022 - 2024 — McMap. All rights reserved.