Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get two columns in part of my PDF document created from Quarto + Latex when working in RStudio?

Pretty simple question: how do I get two columns for part of a document with Quarto?

In particular, a PDF document rendered using PDFlatex. I am working on a Mac in RStudio and rendering via the "render" button.

Here's quarto source code:

---
format: pdf
---

Some heading text.

:::: {.columns}

::: {.column}
text in col1
:::

::: {.column}
text in col2
:::

::::

Some bottom text.

Which renders to this:

reprex

It may be helpful to note that changing "pdf" to "html" in the yaml header and re-rendering yields the desired two-column result:

repres_html

like image 587
DanY Avatar asked Oct 27 '25 14:10

DanY


2 Answers

A "native" quarto solution is to use {layout} instead of {.columns}according to this quarto-dev discussion:

---
format: pdf
---

Some heading text.

:::: {layout="[0.5, 0.5]"}

:::{#firstcol}
text in col1
:::

:::{#secondcol}
text in col2
:::

::::

Some bottom text.

Which renders to:

a_pdf_file

like image 72
DanY Avatar answered Oct 29 '25 15:10

DanY


I believe this is a feature that is not supported natively by Quarto syntax yet, so we will have to revert to using LaTeX syntax to achieve this goal. I'd recommend this as a good start to understanding multiple column layouts in LaTeX. We will need the additional multicol LaTeX package in order to accomplish this. You can load this in Quarto with the following YAML options:

---
format: 
  pdf:
    include-in-header:
      - text: |
          \usepackage{multicol}
---

Then to use the columns in your document, do the following. I am creating a multicols environment, with 2 columns, and I break where one column ends with \columnbreak.

Some initial text at full width for quarto, this should go all the way across
the page

\begin{multicols}{2}

Here is the first column

\columnbreak

Here is the second column

\end{multicols}

Now let us go back to normal text length now that the multicols environment 
has ended.

This produces this effect:

enter image description here

Feel free to ask any additional questions, if this answer works well for you make sure to mark it as accepted for future users.

like image 26
Quinton.Quagliano Avatar answered Oct 29 '25 15:10

Quinton.Quagliano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!