26 Beamer Presentation

In the previous parts of the course, you have learned how to create LaTeX documents. Note that until now you have used the article document format as specified by the \documentclass{article} tag. LaTeX includes many other document classes that you can use. As already mentioned at the beginning of the course, the class is essentially several pre-set document parameters, such as the size of pages, default font sizes and families for different environments, as well as specific commands. In this section, you will learn about another very popular class of LaTeX documents called beamer, which allows you to create presentations, like those you could prepare using Microsoft PowerPoint or similar software.

26.1 First Beamer Presentation

The first example shows how to create a simple Beamer presentation consisting of two slides. Every beamer presentation begins with \documentclass{beamer}. Beamer slides are called frames and every slide is simply a separate frame environment, opened by \begin{frame} and closed by \end{frame}. As you can see, many familiar structures used in the article class, such as itemize, enumerate or vspace also work in the beamer format.

\documentclass{beamer}

\begin{document}
\begin{frame}
    Sample text on the first slide. \\
    A bullet point list:
    \begin{itemize}
        \item A bullet point.
        \item Another bullet point.
        \item Third bullet point.
     \end{itemize}
     
\end{frame}

\begin{frame}
    Sample text on the second slide. \\
    \vspace{1cm}
    A numbered list:
    \begin{enumerate}
        \item One
        \item Two
        \item Three
    \end{enumerate}
\end{frame}

\end{document}

26.2 Title Frame

Most presentations begin with a slide containing its title and author’s credentials. Setting up a title frame in Beamer presentations is like preparing a title page in LaTeX articles. First, you need to specify the title and other details, such as the author’s name, date or institution you work for in the preamble of your document. Then, you simply use the \titlepage tag within the frame environment. Note that in the example it is not necessary to explicitly open and close the frame environment using \begin and \end, as we are using only one tag inside it, and thus we can use a more concise formulation \frame{\titlepage}.

\documentclass{beamer}

\begin{document}
    \begin{frame}
        Sample text on the first slide. \\
        A bullet point list:
        \begin{itemize}
            \item A bullet point.
            \item Another bullet point.
            \item Third bullet point.
        \end{itemize}
\end{frame}

\begin{frame}
        Sample text on the second slide. \\
        \vspace{1cm}
        A numbered list:
        \begin{enumerate}
            \item One
            \item Two
            \item Three
        \end{enumerate}
\end{frame}

\end{document}

26.3 Themes

Like other presentation software, LaTeX comes with several pre-defined themes, as well as allows you to define themes of your own. You can select a pre-defined LaTeX theme using \usetheme{} in the preamble of your presentation. Each of the pre-defined themes can also be customized in terms of its colour scheme, using the \usecolortheme{}. Note that you need to provide it with an existing colour scheme name rather than an arbitrary one. You can find an example list of beamer themes and their colour variants here. One of the important properties of the themes is that they often include a footer or a header which appears on every slide, summarising the information about the presentation, such as author, title, date or current slide number. The presentation information you provide in the preamble can often be too long to fit into the footer/header, so you can provide an optional short or abbreviated version of these. To do that, you can use the form \author[short title]{Full title}, where  short title will appear in the document footer and full title is only displayed on the title page. This can be seen in the example.  

\documentclass{beamer}
\usetheme{madrid}
\usecolortheme{spruce}

\author[Doe]{Jon Doe}
\title[First Beamer]{My First Beamer Presentation}
\subtitle{This is a subtitle}
\institute[PAIS]{University of Warwick \\ Department of Politics and International Studies}
\date[21/02/2020]{21/02/2020 \\ Third LaTeX{} workshop}

\begin{document}

\frame{\titlepage}

\end{document}

26.4 Frame Title

Each frame can also have its heading. This is simply added using the \frametitle{title} tag within the frame environment, where title is the heading you want to give to a certain frame.

\documentclass{beamer}
\usetheme{madrid}
\usecolortheme{spruce}

\author[Doe]{Jon Doe}
\title[First Beamer]{My First Beamer Presentation}
\subtitle{This is a subtitle}
\institute[PAIS]{University of Warwick \\ Department of Politics and International Studies}
\date[21/02/2020]{21/02/2020 \\ Third LaTeX{} workshop}

\begin{document}

\frame{\titlepage}

  \begin{frame}
        \frametitle{This is a title for the current slide}
        Some text.
  \end{frame}

  \begin{frame}
        \frametitle{Another title}
        More text.
  \end{frame}

\end{document}

26.5 Sections

You can divide a beamer presentation into sections and subsections just as you would do in a LaTeX article. Note that these sections should be defined between frame environments, as shown in the example.

\documentclass{beamer}
\usetheme{madrid}
\usecolortheme{spruce}

\author[Doe]{Jon Doe}
\title[First Beamer]{My First Beamer Presentation}
\subtitle{This is a subtitle}
\institute[PAIS]{University of Warwick \\ Department of Politics and International Studies}
\date[21/02/2020]{21/02/2020 \\ Third LaTeX{} workshop}


\begin{document}

  \frame{\titlepage}

  \section{Introduction}

   \begin{frame}
       \frametitle{This is a title for the current slide}
       Some text.
  \end{frame}

\section{Conclusion}

   \begin{frame}
       \frametitle{Another title}
       More text.
  \end{frame}

\end{document}

26.6 AtBeginSection

Note that adding the section did not make any changes to our slide content or titles. This is because, by default, beamer uses section titles only to structure your document (for example, they can be seen when you add a table of contents, which will be discussed later). If you want each section to begin with a section title slide, you need to define that explicitly in the preamble of the LaTeX file, using AtBeginSection{}. You fill the curly braces with a frame, which will appear at the beginning of each section and you can use \insertsectionhead parameter to reference the title of a section. Essentially, you are providing LaTeX with a template of a frame that will be used whenever a new section is started. So, adding this code in the preamble will cause LaTeX to add a slide with vertically centred section title in large bold font at the beginning of each new section. Note that this applies also to subsections – in that case, you would simply use AtBeginSubsection and \insertsubsectionhead.

\AtBeginSection{
    \begin{frame}
        \vfill
        \Huge
        \textbf{\insertsectionhead}
        \vfill
    \end{frame}
}

26.7 Colour Boxes

To improve presentation formatting, it is often good to put your text within a box that matches the presentation theme. This can be particularly useful for section title slides discussed before. Such boxes can be added to a beamer slide using the beamercolorbox environment. It is opened by \begin{beamercolorbox}[options]{color}. There are a number of options that can be used in the brackets to customize the box properties. The most useful ones include:

  • sep=dimension - specifies the separation between the text in the box and the box boundaries (dimension is a length value, for example, 5cm or 12pt)
  • center, right and left – specifies the text alignment within the box
  • round = true or false - determines whether the box corners are rounded or not
  • shadow = true or false – specifies whether a shadow appears behind the box
\AtBeginSection{
\begin{frame}
\vfill
\begin{beamercolorbox}[sep=12pt,center,shadow=true,rounded=true]{frametitle}
\Large
\textbf{\insertsectionhead}
\end{beamercolorbox}
\vfill
\end{frame}
}

The curly braces determine to colour of the box. Note that you cannot use colour names or even colour themes as a keyword in the curly braces – instead, you can only refer to colours explicitly defined for the theme you are using or an object within the beamer presentation – it usually makes sense to set it to ‘title’ or ‘frametitle’, which sets the colour of the box to the same one as the background behind the title of the frame.

26.8 Table of Contents

Adding a table of contents is as easy as it was in the article class – it is done by simply entering the \tableofcontents tag in a separate frame. So the basic table of contents is set by:

\frame{\tableofcontents}

The \tableofcontents tag also comes with some options. A particularly useful one allows to only highlight the number of the current section in the table of contents. This can be done by using:

\frame{\tableofcontents[currentsection]}

If you start your presentation with a table of contents acting as a presentation outline and want to gradually reveal the titles of subsequent sections while discussing the structure, then the pausesections option might be useful. When it’s used, each new element of the table of contents will be introduced on a new slide. 

\frame{\tableofcontents[pausesections]}

26.9 Overlays and Pauses

When delivering a presentation, revealing the entire content of a frame can often be overwhelming for the audience, who may get distracted trying to read everything, instead of listening to the person presenting. To keep everyone focused, it often helps to reveal the information one step at a time. Beamer makes this very easy (arguably easier than other presentation software such as PowerPoint), with the \pause tag. Everything following the tag will appear on the next slide.

\begin{document}
    \begin{frame}
        \frametitle{Title of the slide}
        \pause
        Elements in this slide will appear step-by-step:
        \pause
        \begin{enumerate}
            \item Element One
            \pause
            \item Element Two
            \pause
            \item Element Three
        \end{enumerate}
    \end{frame}
\end{document}

Order of appearance of frame elements can be further customized using overlay specification. The angle brackets (“<” and “>”) used after a markup tag determine on which slides will a certain element or formatting appear. For example, <1> stands for slide number one (of the current frame), <2-4> for the slide range between 2 and 4, and <3,5> for slide 3 and slide 5. The first example shows how it can be applied to a bullet-point list elements appearance:

\frametitle{Title of the slide}
\begin{itemize}
\item<1-4> This appears on all slides. 
\item<2,4> This appears on the second one and the fourth one. 
\item<3> This only appears on the third slide.
\end{itemize}

In the second example, you can see that the overlay specification also works with formattings, such as bold font, italics or font colour. 

\begin{itemize}
\item \textbf<2>{This point will appear in bold on the second slide.}
\item \textit<2>{\color<3>{red}{This point will appear in italics on the second slide and in red on the third.}}
\item \alert<3>{This will be highlighted in in the third slide.}
\end{itemize}

Note that the \alert tag is often used to highlight the text in a colour, which is determined by the presentation theme and colour theme.

26.10 Columns

The beamer class also allows you to control the placement of objects within a frame. The columns environment is used to specify a multi-column frame layout, which offers similar functionality to the ‘two content’ and ‘comparison’ layouts in Microsoft PowerPoint. The environment is opened by \begin{columns}[options] and closed by \end{columns}. The options that can be specified are shown in the table below – you can use two of them, by separating them by commas, for example, \begin{columns}[t,onlytextwidth]. To specify a column, simply use \column{width} within the columns environment, where the width parameter controls the width of the column.

\begin{frame}
\begin{columns}[t]
\column{.3\textwidth}
\textbf{Column 1}: \\
\lipsum[1][1-2]
\column{.3\textwidth}
\textbf{Column 2}: \\
\begin{itemize}
\item One
\item Two
\item Three
\end{itemize}
\end{columns}
\end{frame}

Table 26.1 lists some useful options for the column environment:

Table 26.1: Column Formatting
Option Description
c Central align columns
b Align column bottoms
t Align column tops
totalWidth = Determines total joint width of the two columns
onlytextwidth Equivalent to totalwidth = ∖∖textwidth
T Also top alignment, however using a different method (if formatting problems occur with t, try using T instead)

26.11 Blocks

Blocks are useful when you want to highlight the importance of some text, for example, a quote. They are used to create a separated part of a Beamer frame with its own heading and distinct background color.

\begin{document}
    \begin{frame}
        \begin{block}{\textbf{Important Message}}
            \lipsum[1][1-4]
        \end{block}
        \begin{itemize}
            \item Some
            \item Bullet
            \item Points
        \end{itemize}
    \end{frame}
\end{document}

26.12 Figures and Tables

You can use figures and tables in Beamer presentations just as you would in LaTeX articles. For example, you can present the relationship between two variables in two columns, one showing a regression table and the other the scatter plot of the data.

\begin{Verbatim}
\begin{document}
    \begin{frame}
        \begin{columns}[t]
            \column{.3\textwidth}
            \textbf{Column 1}: \\
            \begin{table}[!htbp] \centering 
                \begin{tabular}{lc} 
                    \\[-1.8ex]\hline 
                    & Regressand \\
                    \hline \\[-1.8ex]
                    Regressor & 0.167$^{***}$ \\ 
                    & (0.002) \\ 
                    & \\ 
                    Constant & 0.843$^{***}$ \\ 
                    & (0.073) \\ 
                    & \\ 
                    \hline \\[-1.8ex] 
                    N & 1,000 \\ 
                    R$^{2}$ & 0.823 \\ 
                    \hline \\[-1.8ex]  
                \end{tabular} 
                \caption{Regression results} 
            \end{table} 
            \column{.3\textwidth}
            \textbf{Column 2}: \\
            \begin{figure}[!htbp]
                \includegraphics[width = \columnwidth]{reg_plot.png}
                \caption{Scatter plot}
            \end{figure}
        \end{columns}
    \end{frame}
\end{document}

26.13 Summary

The functionalities listed in the previous slides are only a very basic list – Beamer offers many more options and graphic structures than you can use – a comprehensive overview is offered by this rather length Beamer documentation.

Important hint: when working with Beamer in practice, sometimes errors may persist when you re-compile the PDF file (by pressing the “play “ button in TeXStudio) even though your code is correct. In that case, this might be due to the auxiliary files created by TeX when you compile the document –a solution that is always worth trying is deleting these files – either by hand or using the “Clean auxiliary files” option in the “Tools” tab of TeXStudio.

To delete all of them, enter the following list into the “file extensions” field: log,aux,dvi,lof,lot,bit,idx,glo,bbl,bcf,ilg,toc,ind,out,blg,fdb_latexmk,fls,snm,nav,synctex.gz