简体   繁体   中英

Two-column mode in standard R Markdown for pandoc pdf output

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 (eg # ... 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM