Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

r - two-column layouts in RStudio presentations/slidify/pandoc

I'm trying to come up with a good system for generating slides and accompanying handouts. The ideal system would have the following properties:

  • beautiful in both presentation (PDF/HTML) and handout (PDF) layouts (handouts should have room for taking notes)
  • embedded R chunks, figures, other JPG/PNG pictures, etc.
  • easy to compose
  • build using command-line tools
  • bibliography support
  • pandoc slide separator format (automatically generate a new slide after headers of a specified level) is preferred
  • I can live with a little bit of additional processing (e.g. via sed), but would prefer not to write a huge infrastructure
  • two-column layouts: there is a SO post on how to get multi-column slides from pandoc, but it is LaTeX- rather than HTML-oriented.
  • ability to adjust sizes of embedded images (other than R-generated figures) and column widths on the fly

Here's what I've discovered so far about the various options:

  • Slidify:
    • doesn't do pandoc slide separator format, although there is a workaround
    • the suggestion for creating handouts is to print to PDF; I'd like to leave room for notes etc. (I could probably figure out a way to do that using something like PDFtk or psnup ...)
  • RStudio presentations (.Rpres files):
    • does lots of things nicely, including multi-columns with specified widths
    • doesn't support pandoc slide separator format
    • I can't figure out what's going on under the hood. There is RStudio documentation that describes the translation process for regular HTML, but it doesn't seem to cover the R presentation format (which isn't quite the same). (I have previously invested some effort in figuring out how to get RStudio-like output via pandoc ...), which means I can't generate slides etc. from the command line.
  • RStudio's Development Version (as of March 2014) comes bundled with Pandoc and version 2 of rmarkdown. It addresses many of the above issues with the .Rpres format.
  • pandoc: may be the only markdown-translator that has features such as footnotes, bibliography support, etc.. I can also use pandoc to generate LaTeX using the tufte-handout class, which meets my criteria of beauty.
    • Unfortunately, it seems not to have built-in two-column format support. Yihui Xie's HTML5 example doesn't show any two-column examples, and it claims (on slide 5) that clicking 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 to be ...
  • LaTeX/beamer: I could simply compose in Rnw (knitr-dialect Sweave) rather than R markdown to begin with. This would give me ultimate flexibility ...
    • despite many years of LaTeX use I do find LaTeX composition more of a pain than markdown composition.

After all that, my specific question is: what's the best (easiest) way to generate a two-column layout for HTML output?

Any other advice will also be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is an old Q, but I was recently plagued by a similar question, here's what I found:

Using the RPres format, two columns can be specified like so (details). Note that RPres can only be converted to HTML by clicking a button in RStudio, there doesn't seem to be any command line method, which is a bit annoying. Despite, that I'd say it is currently the simplest and most flexible method for getting slide columns with markdown:

=== 

Two Column Layout  
===

This slide has two columns

***

```{r, echo=FALSE}
plot(cars)
```

enter image description here

Some flexibility is afforded by adjusting the column proportions:

===

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 with no control over where the break is, which is a bit of a 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 an Rmd file using the beamer_presentation format in RStudio to get two columns like this, but can't run any code in either column, which is a limitation:

---
output: beamer_presentation
---

Two Column Layout 
-------

egin{columns}
egin{column}{0.48extwidth}
This slide has two columns
end{column}
egin{column}{0.48extwidth}
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

Seems like a regular Rnw LaTeX doc is the best way to get columns if you want to use LaTex, not this markdown hybrid (cf. two column beamer/sweave slide with grid graphic)

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

The slidify website has instructions on making two columns here: http://slidify.org/customize.html but it's not clear what has to go into the assets/layouts folder to make it work


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...