29

When rendering html documents with rmarkdown there are ways to make a two columns layout, e.g. here

Is there an easy way to render a pdf document with two column layout? Is there an example code somewhere?

Community
  • 1
  • 1
rdatasculptor
  • 8,112
  • 14
  • 56
  • 81

5 Answers5

33

New pandoc version have made this easier since my original answer. According to pandoc's manual, you can now specify classoptions directly in the YAML front matter:

---
classoption:
- twocolumn
---

The new div notation also allows for inserting two column sections anywhere in the document, working for most formats

:::::::::::::: {.columns}
::: {.column width="40%"}

contents...

:::
::: {.column width="60%"}

contents...

:::
::::::::::::::

Original answer

You can use the article option twocolumn to format the whole document in two columns. Add this to your yaml front matter:

---
output: 
  pdf_document:
    pandoc_args: [
      "-V", "classoption=twocolumn"
    ]
---
scoa
  • 19,359
  • 5
  • 65
  • 80
  • 1
    ok, I see where the second column is supposed to be but all the content is in the first column. How to put content to second column? – Matt Bannert Oct 09 '17 at 19:27
  • 1
    So to start a twocolumn section, you just use \twocolumn, but how do you set it back to onecolumn for subsequent sections (like figures, for instance)? – TheProletariat Nov 29 '17 at 21:33
  • you can use \onecolumn but fine tuning this is hard. You'll find more help on tex.SE: https://tex.stackexchange.com/ – scoa Nov 30 '17 at 10:39
9

More succinctly:

---
output:
  pdf_document:
classoption: twocolumn
---
RTS
  • 882
  • 1
  • 8
  • 13
7

Regarding switching between one and two columns modes in pdf the following snippets work for me

To two column mode:

```{r, echo=FALSE, results='asis'}
cat("\\twocolumn")
```

To one column mode:

```{r, echo=FALSE, results='asis'}
cat("\\onecolumn")
```
juhariis
  • 568
  • 8
  • 15
5

Credit for this answer found here: https://timmurphy.org/2010/06/23/adding-a-two-column-section-to-a-latex-document/

\begin{minipage}[t]{0.5\textwidth}
First Column Goodies.\\
More First Column Goodies.\\
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
Second Column Goodies.\\
More Second Column Goodies.\\
\end{minipage}

Note: VERY important that there is no space between the /end{minipage} and the next \begin{minipage} (not counting comments). Otherwise LaTeX will not render the columns side by side.

TTS
  • 1,818
  • 7
  • 16
2

In addition to scoa's answer, in order to give the columns more space you can add a value to the header-includes:, for example:

---
output:
  pdf_document:
    ...
header-includes:
- \setlength{\columnsep}{18pt}
---
jay.sf
  • 60,139
  • 8
  • 53
  • 110