Example for a Metropolis-themed RMarkdown-driven LaTeX Beamer presentation. If you are interested in this, you probably want to look at the binb package which implements Metropolis (and more) directly from RMarkdown. NB: This dates mostly from 2016.
5.8 Multi-column layout (*)
In addition to the named methods you can also pass an arbitrary function to be used for printing data frames. You can disable the dfprint behavior entirely by setting the option rmarkdown.dfprint to FALSE. Beamer theme (e.g. Beamer color theme (e.g. Beamer font theme (e.g. Illegal parameter number in definiton of beamer frame Pandoc RMarkdown. The prp function from rpart in R only plots a single leaf node. R/beamerpresentation.R defines the following functions: patchbeamertemplate patchbeamertemplateparagraphspacing patchbeamertemplatepagenumber beamerpresentation rstudio/rmarkdown source: R/beamerpresentation.R.
Pandoc’s Markdown supports the multi-column layout for slides but not other types of documents. In this recipe, we show how to use the multi-column layout in normal HTML documents and LaTeX documents. This recipe was inspired by Atsushi Yasumoto’s solutions to the knitr issue https://github.com/yihui/knitr/issues/1743.
Beamer Rmarkdown Error
The recipe will be much simpler if you only need to consider HTML output, because arranging HTML elements side by side is relatively simple via CSS. It will be even simpler if you only need to arrange the text output of a code chunk side by side. Below is the first example:
The CSS attribute display: inline-block;
means the output code blocks (i.e., the <pre>
tags in HTML) should be displayed as inline elements. By default, these blocks are displayed as block-level elements (i.e., display: block;
) and will occupy whole rows. The chunk option collapse = TRUE
means the text output will be merged into the R source code block, so both the source and its text output will be placed in the same <pre>
block.
If you want to arrange arbitrary content side by side in HTML output, you can use Pandoc’s fenced Div
. The name “Div” comes from the HTML tag <div>
, but you can interpret it as an arbitrary block or container. A Div
starts and ends with three or more colons (e.g., :::
). A Div
with more colons can contain Div
s with fewer colons. An important and useful feature of the fenced Div
is that you can attach attributes to it. For example, you can apply the CSS attribute display: flex;
to an outside container, so that the inside containers will be placed side by side:
In the above example, the outside Div
(::::
) contains two Div
s (:::
). You can certainly add more Div
s inside. To learn more about the very powerful CSS attribute display: flex;
(CSS Flexbox), you may read the guide at https://css-tricks.com/snippets/css/a-guide-to-flexbox/. The CSS Grid (display: grid;
) is also very powerful and can be used in the above example, too. If you want to try it, you may change display: flex;
to display: grid; grid-template-columns: 1fr 1fr; grid-column-gap: 10px;
. See the guide at https://css-tricks.com/snippets/css/complete-guide-grid/ if you want to learn more about the grid layout.
Beamer Rmarkdown Spacing
It is trickier if you want the layout to work for both HTML and LaTeX output. We show a full example below that works for HTML documents, LaTeX documents, and Beamer presentations:
FIGURE 5.3: A two-column layout that works for HTML, LaTeX, and Beamer output.
Figure 5.3 shows the output. In this example, we used an outside Div
with the class .cols
and three inside Div
s with the class .col
. For HTML output, we introduced an external CSS file columns.css
, in which we applied the Flexbox layout to the outside Div
so the inside Div
s can be placed side by side:
For LaTeX output (pdf_document
), we have to introduce some dirty hacks stored in columns.tex
to the LaTeX preamble to define the LaTeX environments cols
and col
:
The col
environment is particularly complicated mainly because Pandoc starts a new paragraph for each Div
in LaTeX output, and we have to remove these new paragraphs. Otherwise, the Div
s cannot be placed side by side. The hacks were borrowed from https://tex.stackexchange.com/q/179016/9128.
For Beamer output, we apply the same hacks in columns.tex
. Please note that Pandoc has provided some special Div
’s for slide shows, such as ::: {.columns}
, ::: {.column}
, and ::: {.incremental}
. Because they already have their special meanings, you must be careful not to use these types of Div
’s if you intend to convert a Div
to a LaTeX environment in the way mentioned in this section. That is why we did not use the Div
types columns
or column
, but chose to use cols
and col
instead.
Beamer Rmarkdown Box
For more information about fenced Div
’s, please refer to Section 9.6.