Two-column layouts in RStudio / slidify / pandoc presentations

I am trying to create a good system for creating slides and accompanying handouts. An ideal system will have the following properties:

  • beautiful both in the presentation (PDF / HTML) and in handouts (PDF) (in handouts there should be a place for notes).
  • embedded R fragments, drawings, other JPG / PNG images, etc.
  • easy to compose
  • build using command line tools
  • bibliography support
  • pandoc slide separator format (automatically generate a new slide after the headings of a given level).
  • I can live with a little extra processing (e.g. via sed ), but would prefer not to write a huge infrastructure
  • two-column layouts : there is an SO post on how to get slides with multiple columns from pandoc , but this is LaTeX and not HTML oriented.
  • the ability to adjust the size of embedded images (except for R-generated shapes) and column widths on the fly

Here is what I have discovered so far about the various options:

  • Slidify:
    • pandoc does not make the format of the slide separator, although there is a workaround
    • the proposal for the creation of handouts is a PDF print; I would like to leave space for notes, etc. (I could probably find a way to do this using something like PDFtk or psnup ...)
  • RStudio presentations ( .Rpres files):
    • does a lot of things beautifully including several columns with a specified width
    • does not support pandoc slide separator format
    • I can’t understand what is happening under the hood. There is an RStudio documentation that describes the translation process for regular HTML, but does not seem to cover the R presentation format (which is not exactly the same). (I previously put some effort into figuring out how to get an RStudio-like output via pandoc ..., which means that I cannot generate slides, etc. from the command line.
  • The RStudio Development Version (as of March 2014) comes bundled with Pandoc and version 2 rmarkdown . It addresses many of the above issues in .Rpres format.
  • pandoc : may be the only pointer that has features such as footnotes, bibliography support, etc. I can also use pandoc to create LaTeX using the tufte-handout class that matches my beauty criteria.
    • Unfortunately, it does not seem to have built-in support for two columns. The Yihui Xie HTML5 example does not show any two-column examples, and it claims (on slide 5) that pressing the Knit HTML button in RStudio is equivalent to pandoc -s -S -i -t dzslides --mathjax knitr-slides.md -o knitr-slides.html but it doesn't seem ...
  • LaTeX / beamer: I could just compose in Rnw (knitr-dialect Sweave), not an R markdown. This will give me maximum flexibility ...
    • Despite using LaTeX for many years, I find the LaTeX composition more painful than the markdown composition.

In the end, my specific question is: what is the best (easiest) way to create a two-column layout for HTML output?

Any other recommendations would be appreciated.

+55
r rstudio knitr r-markdown slidify
Dec 30 '14 at 20:53
source share
7 answers

Now I have what I consider to be a reasonable solution, which should apply at least to ioslides based ioslides and, possibly, (?) To other HTML5-based formats. Running here , I added

 <style> div#before-column p.forceBreak { break-before: column; } div#after-column p.forceBreak { break-after: column; } </style> 

to the beginning of my document; then placing <p class="forceBreak"></p> inside the slide with {.columns-2} breaks the column at this point, for example

 ## Latin hypercube sampling {.columns-2} - sample evenly, randomly across (potentially many) uncertain parameters <p class="forceBreak"></p> ![](LHScrop.png) [User:Saittam, Wikipedia](https://commons.wikimedia.org/wiki/File:LHSsampling.png#/media/File:LHSsampling.png) 

Perhaps an even better way, but it doesn't hurt too much.

@ChrisMerkord points out in the comments that

 .forceBreak { -webkit-column-break-after: always; break-after: column; } 

worked (I did not test ...)

+11
Feb 05 '16 at 23:43
source share

This is an old question, but recently I was tormented by a similar question, here is what I found:

Using the RPres format, you can specify two columns as follows ( details ). Please note that RPres can only be converted to HTML by clicking a button in RStudio. There seems to be no command line method, which is a little annoying. Despite this, I would say that this is currently the easiest and most flexible way to get markdown slide columns:

 === Two Column Layout === This slide has two columns *** '''{r, echo=FALSE} plot(cars) ''' 

enter image description here

Some flexibility is provided by adjusting the proportions of the column:

 === Two Column Layout === left: 30% This slide has two columns *** '''{r, echo=FALSE} plot(cars) ''' 

enter image description here

With rmarkdown, we can get two columns, but without control of where the gap is, which is a small problem:

 --- output: ioslides_presentation --- ## Two Column Layout {.columns-2} This slide has two columns '''{r, echo=FALSE} plot(cars) ''' 

enter image description here

We can also mix markdown and LaTeX in the Rmd file using the beamer_presentation format in RStudio to get two such columns, but we cannot run any code in any of the columns, which is a limitation:

 --- output: beamer_presentation --- Two Column Layout ------- \begin{columns} \begin{column}{0.48\textwidth} This slide has two columns \end{column} \begin{column}{0.48\textwidth} If I put any code in here I get an error, see https://support.rstudio.com/hc/communities/public/questions/202717656-Can-we-have-columns-in-rmarkdown-beamer-presentations- \end{column} \end{columns} 

enter image description here

It looks like a regular Rnw LaTeX document is the best way to get columns if you want to use LaTex and not this markdown hybrid (see the two-column beamer / sweave with grid graphics )

In all of the above, an image can be placed in a column.

The slidify website has instructions for creating two columns: http://slidify.org/customize.html, but it’s not clear what needs to be done to make it work in the assets / layouts folder.

+26
Dec 16 '14 at 2:00
source share

I got an idea from HERE , the main solutions were:




 ### Function *inner_join* . . . '<div style="float: left; width: 50%;">' ''' {r, echo = FALSE, results = 'markup', eval = TRUE} kable(cbind(A,B)) ''' '</div>' '<div style="float: right; width: 50%;">' '''{r, echo = TRUE, results = 'markup', eval = TRUE} inner_join(A,B, by="C") ''' '</div>' 



+6
Jul 06 '16 at 12:32
source share

There is a workaround for projector error.

In short: The error is related to the pandoc conversion mechanism, which treats everything between \begin{...} and \end{...} as TeX . This can be avoided by giving a new definition for begin{column} and end{column} in the yaml header.

Create mystyle.tex and write there:

 \def\begincols{\begin{columns}} \def\begincol{\begin{column}} \def\endcol{\end{column}} \def\endcols{\end{columns}} 

In the Rmd file, use these new definitions

 --- output: beamer_presentation: includes: in_header: mystyle.tex --- Two Column Layout ------- \begincols \begincol{.48\textwidth} This slide has two columns. \endcol \begincol{.48\textwidth} '''{r} #No error here i can run any r code plot(cars) ''' \endcol \endcols 

And you will get: enter image description here

+6
Nov 21 '17 at 8:35
source share

So far, I have not been able to do anything better than hack my little markup on top of the rmd format: I call my source file rmd0 and run a script, including this sed tidbit, to translate it to rmd before calling knit :

 sed -e 's/BEGIN2COLS\(.*\)/<table><tr><td style="vertical-align:top; width=50%" \1>/' \ -e 's/SWITCH2COLS/<\/td><td style="vertical-align:top">/' \ -e 's/END2COLS/<\/td><\/tr><\/table>/' ... 

There are several reasons why I don’t like it. (1) This is ugly and specialized, and I have no particular way to allow extra arguments (e.g. relative column widths, alignment, etc.). (2) It must be changed for each output format (for example, if I need LaTeX / beamer output, I will need to replace \begin{columns}\begin{column}{5cm} ... \end{column}\begin{column}{5cm} ... \end{column}\end{columns} instead \begin{columns}\begin{column}{5cm} ... \end{column}\begin{column}{5cm} ... \end{column}\end{columns} (as it turned out, I want to ignore the formatting of two columns when I make LaTeX format handouts, so it's a little easier, but it's still ugly).

Slidify may be the answer.

+3
Jan 13 '14 at 23:14
source share

You can use the notation fenced_divs or : to create columns or "Layout with two contents." See also this page to learn more about notation.

 ## Slide With Image Left ::: columns :::: column left :::: :::: column right '''{r your-chunk-name, echo=FALSE, fig.cap="your-caption-name"} knitr::include_graphics("your/figure/path/to/the-image.pdf") #The figure will appear on the right side of the slide... ''' :::: ::: 

Since pandoc 2+ , which supports notation, was implemented in RStudio v1.2+ , you may need to install RStudio v1.2+ . Installation is quite simple (at least in my case); Just download and install RStudio v1.2+ . During the installation process, the previous version of RStudio on your computer will be replaced with a new one without manually deleting it.

Notation : can be used even with .Rmd files with the beamer_presentation option, as well as when creating HTML slides. Thus, we do not need to mix markdown and LaTeX notations in one file, nor add additional codes anymore: just a .Rmd file, like you .Rmd another .Rmd with other options.

0
Dec 28 '18 at 9:27
source share

Not a direct solution, but the Xaringan package https://github.com/yihui/xaringan/ works for me. This is based on remark.js . In the default template, you can use .pull-left[] and .pull-right[] . Example: https://slides.yihui.name/xaringan/#15 . You only need a minimal setup of existing .rmd files.

0
Dec 29 '18 at 6:01
source share



All Articles