2

I am creating a .pdf using R Markdown. I would like to have a section of text in two column format, and then follow that with a graph (or table, photo, etc.) that takes up the entire width of the page, and then return to two column text. I am new at Markdown / LaTex / Pandoc and I cannot figure out how to do it.

This answer by @AlisonShelton appears to be what I want, but when I run it I get this error in the RStudo R Markdown console:

! Undefined control sequence.
l.87 \btwocol
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43

I have successfully used this method by @scoa to make a two column .pdf, but I don't know how go back and forth between one and two columns using this.

Here is some sample code for testing purposes

    ---
    title: "Test"
    output: pdf_document
    ---

    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```

    ## Two columns of text

    This seciton should be in two column format.
    Here are a bunch of ? to make it longer: ???????????????????????????????????????????????????????????????????????????????
    ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????

## Once column section. 
This part should be the whole page width
```{r plot}
plot(rnorm(20),rnorm(20))
```

## Now 2 columns again
This section should go back to two columns  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
John Paul
  • 12,196
  • 6
  • 55
  • 75

1 Answers1

2

What you can do is first, to add -- as you stated -- pandoc_args: ... into your YAML header. Second, there are a few LaTeX solutions around (like this or this one) which won't work for RMarkdown. The only way I found so far is to use \onyecolumn / \twocolumn -- just with the drawback of the page breaks. But perhaps you can live with it until there's a better solution.

---
title: "Test"
output:
  pdf_document: 
    pandoc_args: [
      "-V", "classoption=twocolumn"
    ]
  html_document: default
header-includes:
- \usepackage{lipsum}  # just used for producing example text in document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Two columns of text
\lipsum[1-7]
\onecolumn

## Once column section. 
This part should be the whole page width
```{r plot}
plot(rnorm(20),rnorm(20))
```
\lipsum[1]
\twocolumn

## Now 2 columns again
This section should go back to two columns
\lipsum

\begin{table*}
This is nice, but won't work with R chunks or headers. And you'll have to format with LaTeX code (e.g. \textbf{Foo blaah}).
\lipsum[1]
\end{table*}
\lipsum
jay.sf
  • 60,139
  • 8
  • 53
  • 110