0

I'm looking for a solution to the RMarkdown 2-column question. The columns.sty works great in Beamer but not in article or document mode. What I'm looking for is a way to switch from full width to two column text in which the RMarkdown parameters are recognized (minipage doesn't allow this, apparently) and where I can execute a chunk for a plot or table or pander output, and then back again to full width, w/o creating a new page as with \twocolumn \onecolumn. The classoption: twopage approach doesn't work for me for some reason as suggested here. Am I asking too much? Any help with a fully working example would be great!

Here's an example of the use of the class option 'twocolumn' in the yaml section. A two column section starts with \begin{minipage} and ends with \end{minipage}. This will produce a two column section but, as far as I can tell, this also creates a latex-only section because RMarkdown parameters (e.g. # ... for a heading) create an error on rendering to a pdf (that's what I want).

title: "Two column test"
author: "David Stevens"
date: "10/19/2020"
output:
  pdf_document: default
  html_document: default
classoption: twocolumn
---

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

### Left column  

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

Produces the error

output file: Two-Column-Tester.knit.md

! You can't use `macro parameter character #' in horizontal mode. l.81 # ## Left column

Error: LaTeX failed to compile Two-Column-Tester.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Two-Column-Tester.log for more info. Execution halted

The line ### Two column renders fine outside the two-column section but when moved inside the two column section throws an error

Dr Dave
  • 453
  • 1
  • 4
  • 11
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Oct 20 '20 at 02:35

1 Answers1

0

Would you consider work with existing styles? The rticles packages has a large number of those. I by coincidence I just updated the 'gallery' of styles included in that package which you can browse at this link. There is also one large aggregated gif with all.

We also created the pinp package are derived version of the 'pnas' style in rticles. I use that in several packages for the vignette.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725