To create a Beamer presentation from R Markdown you specify the beamer_presentation
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 (----
). For example here’s a simple slide show:
---
title: "Habits"
author: John Doe
date: March 22, 2005
output: beamer_presentation
---
# In the morning
## Getting up
- Turn off alarm
- Get out of bed
## Breakfast
- Eat eggs
- Drink coffee
# In the evening
## Dinner
- Eat spaghetti
- Drink wine
----
![picture of spaghetti](images/spaghetti.jpg)
## Going to sleep
- Get in bed
- Count sheep
Within R Markdown documents that generate PDF output you can use raw LaTeX and even define LaTeX macros. See the documentation on Raw TeX for details.
You can render bullets incrementally by adding the incremental
option:
---
output:
beamer_presentation:
incremental: true
---
If you want to render bullets incrementally for some slides but not others you can use this syntax:
> - Eat eggs
> - Drink coffee
You can specify Beamer themes using the theme
, colortheme
, and fonttheme
options:
output:
beamer_presentation:
theme: "AnnArbor"
colortheme: "dolphin"
fonttheme: "structurebold"
---
The toc
option specifies that a table of contents should be included at the beginning of the presentation (only level 1 headers will be included in the table of contents). For example:
---
output:
beamer_presentation:
toc: true
---
The slide_level
option defines the heading level that defines individual slides. By default this is the highest header level in the hierarchy that is followed immediately by content, and not another header, somewhere in the document. This default can be overridden by specifying an explicit slide_level
:
---
output:
beamer_presentation:
slide_level: 2
---
There are a number of options that affect the output of figures within Beamer presentations:
fig_width
and fig_height
can be used to control the default figure width and height (6 x 4.5 is used by default)
fig_crop
controls whether the the pdfcrop utility (if available) is automatically applied to pdf figures (this is true by default).
fig_caption
controls whether figures are rendered with captions (this is true by default).
dev
controls the graphics device used to render figures (defaults to pdf)
For example:
---
title: "Habits"
output:
beamer_presentation:
fig_width: 7
fig_height: 6
fig_caption: true
---
You can enhance the default display of data frames via the df_print
option. Valid values include:
Option | Description |
---|---|
default | Call the print.data.frame generic method |
kable | Use the knitr::kable function. |
tibble | Use the tibble::print.tbl_df function. |
For example:
---
title: "Habits"
output:
html_document:
df_print: kable
---
The highlight
option specifies the syntax highlighting style. Supported styles include “default”, “tango”, “pygments”, “kate”, “monochrome”, “espresso”, “zenburn”, and “haddock” (specify null to prevent syntax highlighting):
For example:
---
title: "Habits"
output:
beamer_presentation:
highlight: tango
---
R Markdown documents are converted to PDF by first converting to a TeX file and then calling the LaTeX engine to convert to PDF. By default this TeX file is removed, however if you want to keep it (e.g. for an article submission) you can specify the keep_tex
option. For example:
---
title: "Habits"
output:
beamer_presentation:
keep_tex: true
---
You can do more advanced customization of PDF output by including additional LaTeX directives and/or content or by replacing the core pandoc template entirely. To include content in the document header or before/after the document body you use the includes
option as follows:
---
title: "Habits"
output:
beamer_presentation:
includes:
in_header: header.tex
before_body: doc_prefix.tex
after_body: doc_suffix.tex
---
You can also replace the underlying pandoc template using the template
option:
---
title: "Habits"
output:
beamer_presentation:
template: quarterly_report.tex
---
Consult the documentation on pandoc templates for additional details on templates. You can also study the default Beamer template as an example.
By default R Markdown is defined as all pandoc markdown extensions with the following tweaks for backward compatibility with the markdown package:
+autolink_bare_uris
+ascii_identifier
+tex_math_single_backslash
You can enable or disable markdown extensions using the md_extensions
option (you preface an option with -
to disable and +
to enable it). For example:
---
title: "Habits"
output:
html_document:
md_extensions: -autolink_bare_uris+hard_line_breaks
---
The above would disable the autolink_bare_uris
extension and enable the hard_line_breaks
extension.
For more on available markdown extensions see the pandoc markdown specification.
If there are pandoc features you want to use that lack equivilants in the YAML options described above you can still use them by passing custom pandoc_args
. For example:
---
title: "Habits"
output:
beamer_presentation:
pandoc_args: [
"--no-tex-ligatures"
]
---
Documentation on all available pandoc arguments can be found in the pandoc user guide.