To create a Beamer presentation from R Markdown you specify the beamerpresentation output format in the front-matter of your document. You can create a slide show broken up into sections by using the # and ## heading tags (you can also create a new slide without a header using a horizontal rule (-). Apr 11, 2021 I have a markdown beamerpresentation. I have changed the biblio-style to apalike, but I am not getting the expected result. I used Grady et al. (2019) as an example, which is cited on the APA webs.
Since I discovered R Markdown I really like to prepare my presentation with it, especially because I can include a piece of code (R, Python, …) well formatted. Last week I did in Strasbourg the first meeting for the local R-Ladies and I prepared my presentation with R Markdown, not because I had code to show but because I was talking about R. I modified an older beamer template that I used during my PhD and I created this new template. The first thing to modify a beamer template for creating a new one, is to make a file .sty like this “beamerthemeName.sty”, where ‘Name’ should be the name you want to give to your template and that you will use in beamer and R Markdown. In my case the name of my template was RLadies. To create this file I chose an existing beamer theme, in this case was “Pittsburgh”, and I set the color I liked (R-Ladies colors) and define some rules for header and slides. The code for the beamerthemeRLadies.sty is the following:
Modifying this code, changing the theme, colours etc. you can obtain a new template for your beamer and RMarkdown presentations, as you like.
You can define the header of Rmarkdown like this:
And using this theme I created a pdf for the first meeting of R-Ladies Strasbourg.
- Congressman Rick Astley makes another pledge on the campaign trail
I’ll keep the introduction to this post fairly simple. It’s back-to-school season for professors, which means it’s time to prepare syllabi and lectures for the coming school year. I realized as I was doing some website maintenance that I never formally introduced the most common R Markdown template that I use: my Beamer template. Over four years ago, I talked a little about why people should move from Beamer to R Markdown and use the latter as a wrapper for the former. However, I’ve tweaked my Beamer templates so much since that I should probably describe it more in detail.
Consider this another installment in my catalog of posts on R Markdown, complementing my suite of templates for things like academic manuscripts, CVs, syllabi, Xaringan presentations, and memos (among other templates). You can also skip this and head straight to my Github repo for all these things.
Getting Started with the YAML
Here is what the YAML will resemble for my standard Beamer presentation.
Long-time users of my templates or R Markdown should recognize a fair bit here. Make title:
the topic of your presentation. subtitle:
is optional, but try to use it since it looks nice and fleshes out the title page. The author:
field should be who you are (or me, you’re free to make everything about and by me). The institute:
field should be your department or employer.
The titlegraphic:
field should be a relative(-ish) path to a brand marker for your university or employer. LaTeX (as far as I know) is a bit wonky about paths. My template specifies this field like this, if you wanted to see what it looks like under the proverbial hood.
Thus, start a relative(-ish) path to your university’s “brand” marker, wherever it is on your hard drive. If you’re a new student trying to figure this stuff out for the first time and are unaware what I mean by “brand” in the context of universities: trust me; your university has a brand “guideline” and has copious guides to “protecting” the “brand.” Your university speaks of itself like a corporation and would hire two dozen Darren Rovells to “protect” and “promote” the “brand” if they haven’t already. Don’t believe me? Here’s my beloved alma mater trying to file a trademark for the most common word in the English language to protect its “brand” by arguing the most common word in the English language is actually its intellectual property.
Just search “brand” on your university’s website and you should be good to go from there. For what it’s worth, the titlegraphic:
field is optional. You can omit this if you’d like, but then you should make the institute:
field your university or employer.
The stuff under output:
is worth belaboring a little bit. template:
should obviously be where the actual .tex template is and keep_tex:
is optional if you want to keep or discard the intermediate .tex file for the Beamer presentation. Thereafter, you can use the latex_engine:
option to favor xelatex (as I do now) over pdflatex (which I used to use back when I first created my template). The only real reason for this switch is if you wanted to customize the font options (more on that later). If you set latex_engine: xelatex
, you should also set dev: cairo_pdf
. This will allow you to use some fancy fonts in your ggplot graphs.
As a final little note on the stuff under output:
, I typically set slide_level: 3
so that three pound signs (###) denote a new slide. Two pound signs are a subsection and one pound sign is a section.
Beamer Rmarkdown
The final set of options are stuff I’ve added over the years. Most computer screens these days are widescreen, even the computers you’ll find in your class room. I want to leverage this space as well as I can. Thus, I created a make149:
option so my presentations can have a 14:9 aspect ratio. This is optional. Commented out, the presentation would be the default aspect ratio for a Beamer presentation. I’m pretty sure that’s 4:3.
Finally, if you’ve set latex_engine: xelatex
, why not give yourself some fonts of choice? My main font (mainfont:
) is Open Sans while the title fonts (titlefont:
, for slides and the title page) is Titillium Web. You may recognize these fonts on my website as well. For as much as I just riffed on universities being snobby about their “brand”, I suppose I have mine as well.
Add Your Own Colors to the .tex File
Assuming you don’t want your presentations to be orange and purple ahem, “Clemson Orange” and “Regalia”, head over to the .tex file and find the stretch of code you see below.
Beamer Markdown Table
Change or add anything you see fit for your purposes. I always found hex color codes to be intuitive, so that’s how I enter them.
You may also want to change the colors for your frame titles and the like. Those are options are listed below.
I’m of the mentality that most Beamer presentations waste precious space with things like overhead or side navigation panels. It’s why omit those things entirely, even the navigation symbols (i.e. the tribal arm band tattoo of Beamer presentations).1 It’s more important to make the presentation informative than, well, gaudy. Yeah, I’m especially looking at you, Palo Alto. However, I do have a subtle cosmetic touch at the footline that has some of these colors. Go a bit further down until you find this stretch of code and change the Clemson color codes you see.
There are some other final color options here you may want to change if you want to de-Clemson your presentation.
A Sample R Markdown Slide
Of course, no sample R Markdown Beamer presentation of mine is complete without weirdness. My sample presentation (which shows what the finished product looks like) riffs on using pop culture inanities as illustrations of political science concepts, so here’s “Rickrolling” toward an illustration of median voter theorem.
We can visualize median voter theorem accordingly, which pits Congressman Astley’s campaign pledges against a hypothetical rival on the distribution of preferences for emotional support.
According to this graph, Congressman Astley comfortably secures re-election against his rival because his policy package of emotional support is closer to the median voter.
Markdown Beamer Columns
Replication, and Such
You can find the files to reproduce this presentation here on my Github. The template is here. The R Markdown file of the sample presentation is here and this PDF shows what the finished product looks like.
Listen; I get it. You’ve been to Cabo, but you didn’t need to get that to show everyone you made that trip. In fact, stop showing that thing to me. I didn’t ask to see it in the first place. ↩