How make 2 column layout in R markdown when rendering pdf?
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.
More succinctly:
---
output:
pdf_document:
classoption: twocolumn
---
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"
]
---
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")
```