How make 2 column layout in R markdown when rendering pdf?

守給你的承諾、 提交于 2019-12-18 12:18:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!