Custom LaTeX Beamer style templates for rmarkdown

I’ve been producing presentations via R using rmarkdown and outputting to either ioslides or slidify. That was excellent, because I could provide a CSS that customised the look and feel (relatively) easily*.

However, when I wanted to produce a PDF version, I couldn’t make ones that look as good as the pure LaTeX versions I could make on So I started RTFMing when I wanted to replicate the look and feel from my presentation, The LaTeX Show.

I didn’t want to spend a huge amount of time on it, so this little story of hack and slash may feel a bit dirty to you!

In my LaTeX deck, I had a bunch of associated .sty files – I copied these down into the directory with my .Rmd file. I then passed in the YAML header theme: m and hit Compile PDF in Rstudio.

It errored!

But that was only to be expected because I was in a different environment etc, so I started looking at the error messages and commenting out bits of the style until it worked. Stuff included fonts, needing XeLaTeX, and some missing packages.

It still didn’t work!

I eventually got to an error regarding an unknown Shaded environment. Swift googling told me that this is sometimes caused by out of date pandoc templates so I went to the github repo & copied the latest beamer template into a local .tex file and gave that file name in the YAML header for the template.

Et voila!

A consistently themed presentation written in rmarkdown and rendered in ever so pretty LaTeX, was achieved in about half an hour of reading, hacking, and googling. You can view my working example on github and have a play yourself.

* Finding out what elements need styling can be a bit painful – if you don’t already have it, I recommend (as per Hadley Wickham’s recommendation in rvest) that you use Selector Gadget for working out what elements you need to use. You can also use Chrome’s developer functionality (hit F12) which allows you to real-time tweak some values and see what effect it has.