
using Quarto & Reveal.js
Spelman College WiSTEM
7/19/23
These slides are rendered to fancy HTML under the hood using a JavaScript package called reveal.js1.
In some ways, HTML slides are less flexible. You don’t get a point-and-click interface to put things on slides. If you need fancy animations and layout tools, you might prefer to use PowerPoint or Keynote.
However, when you are primarily presenting the output of code, HTML slides allow you to tweak your code without having to constantly replace graphs.
And you can still make slides that are aesthetically pleasing and clear to read.1
Reveal.js has some built-in themes1 you can use.
The easiest way to add some custom flavor is to start with a slide theme that does most of what you want, and then overwrite some of the defaults.
You can set those aesthetic variables in a Sass1 code file, and then tell your code document to refer to that theme file when styling the presentation.
In the external Sass file, you can set variables for things like slide and text color1.
You can also use custom fonts from Google Fonts.
You’ll need to import these in the Sass file.
(The way R gets custom fonts on graphs is different from the way reveal.js gets custom fonts on slides, so you have to import your fonts twice.)
On the Google Fonts page, select the fonts and weights you want to import.
Then, use the selection panel on the top right to get the font import code.
Choose the @import option to get the Sass-compatible code.

Copy and paste the middle line of code (just the line starting with @import) into the top of your Sass file.
Then, set the font variables to use the font you’ve just imported:
The slides will attempt to use the fonts in the priority order you specify.
Including the backup fonts after the first one ensures you have some control even if the Google fonts fail to import for some reason.
For slide-specific background images, you can set your desired background image as a slide property on the slide title line.
The background image can either be hosted on the web, or it can be uploaded to your RStudio Cloud project. You’ll need to give the correct path to the image either way.
If your background image is on the darker side, set background-color="black" as well, even though it won’t be visible. This will trigger the text to print white on top of the background image.
You can also change background-opacity to make your background image appear more muted.
The basic Markdown syntax for placing an image on a slide is:
You can modify the image alignment by setting an extra setting at the end of your image embedding code.
In your image embedding code, you can use the .absolute property to set xy coordinates on your slide for the picture to appear at.

Be careful with positioning! Absolute-placed images will appear on top of text.
You can place content in columns using container1 syntax.


To create column containers, the syntax looks like:
You can even put code chunks and plots in column containers.
You will need to manually change the aspect ratio of your plots to fill the column space, though.


Use the fig-asp chunk setting, set with the special settings comment #| to set your desired aspect ratio (height/width).
You may also want to make plot text extra large to compensate for the smaller plot.
You can also embed YouTube videos. Video containers have to be specified with two sets of curly braces AND carets, like below:
# DO NOT INCLUDE THE BACKSLASH IN YOUR REAL CODE!
# It's only here to make the rest of the code show up in the slide
{{\< video url/to/video width="100%" height="85%" >}}You do need to set the width and height manually, because the default video size is tiny.
In general, I recommend building slide content incrementally whenever possible.
Slowly adding information onto slides helps keep your audience focused on whatever you’re currently talking about. Help reduce their attention load!
There are a couple features you can use to turn on incremental slide builds.
First, in the header of your document, set incremental: true in the sub-settings for reveal.js slides so that by default, any numbered or bullet-pointed list will animate in one at a time.
(If you then want to turn incremental building off for any list, you can… but why would you? 😛)
To make any arbitrary content on your slide animate in one at a time, divide up lines in your main text with three periods separated with spaces: . . .
If the incremental build doesn’t render, make sure you have those empty lines above and below the . . .
(This might happen if you want to do an incremental build in between a regular-text section and a plot that comes out of a code chunk.)
Using the same ::: container syntax as you can use for adding things like columns, you can also add speaker notes onto slides.
Hit the s key (for speaker!) on this slide to open a second browser window with the speaker notes. As long as either the slides window or the speaker notes window is the active window, you can advance your slides. The speaker notes window also features:
Guide to customizing R slides - Monica Thieu