问题
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?
回答1:
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"
]
---
回答2:
More succinctly:
---
output:
pdf_document:
classoption: twocolumn
---
回答3:
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")
```
回答4:
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}
---
回答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.
来源:https://stackoverflow.com/questions/34808612/how-make-2-column-layout-in-r-markdown-when-rendering-pdf