Stage 6 · Production, macros and packages 45 / 48 ≈ 16 min read

LaTeX Beamer: Building a Presentation Slide by Slide

Beamer looks like a document class that makes slides and behaves like a document class the whole way through — until a frame overflows, an overlay jumps, or a verbatim line fails to parse. It is a presentation model with its own geometry, its own page numbering and its own way of deciding what appears when. Here is that model, plus the theme and note machinery that turns it into a deck you can actually present.

    A frame is a box, and overlays are extra pages

    The class writes one PDF page per frame — and one per overlay within a frame. When you put \pause or an overlay spec in a frame with three reveals, beamer builds four pages and names them the same in the outline. That is the whole model: no animation, no viewer state, just more pages, which is why the PDF works in any reader and why page numbering in a deck needs thinking about.

    The canvas is not a paper size you chose. The default is 12.80cm × 9.60cm; aspectratio=169 switches to 16.00cm × 9.00cm, and the other named values are 43 (default), 32, 54, 149, 1610, 141 and 2013, with any bare number treated as a ratio. Geometry comes from the class: one centimetre left and right, none top and bottom, plus a half-centimetre head. Which is why \textwidth is 10.8cm by default and 14cm in 16:9 — narrower than an article's 15.2cm, so anything you previously sized in centimetres is wrong.

    The frame body is typeset into a box before the page is assembled. Consequences: content that does not fit produces an Overfull \vbox and simply runs off the bottom rather than reflowing; vertical space at the end of a frame is not what you wrote; and the frame options [t], [b], [c] (default centred), [s] and [shrink] are about where that box sits, not about making it smaller. [shrink] is the emergency valve — a frame that needs it is a frame that should be two.

    Bibliographies, long lists and anything that genuinely must run over several slides get [allowframebreaks], which splits at page-break points and numbers the parts 1/n, 2/n; allowframebreaks=0.9 sets how full a page must be before it splits, and \framebreak forces a cut. Overlay specs are not allowed inside an allowframebreaks frame: beamer cannot know which part of the split a given overlay belongs to.

    Anatomy of a beamer frame: paper size, margins, headline, frame title, body and footline regions 4:3 DEFAULT · PAPER 12.80cm × 9.60cm · GEOMETRY hmargin=1cm, vmargin=0 headline · frame title + navigation symbols body = \textwidth tall block \begin{block}{Claim} … \end{block} everything is inside one box that the frame routine measures; overflow is a warning, not a reflow — that is why “Overfull vbox” means split the frame frametopskip / framebottomskip [t] [b] [c] [s] [shrink] pick the glue footline · page number, section, author short title left margin 1cm = the only horizontal padding beamer adds \paperwidth 12.80cm → \textwidth 10.80cm ASPECT RATIO CHANGES THE CANVAS, NOT THE TYPE aspectratio=169 → 16.00 × 9.00cm \textwidth becomes 14.0cm, \textheight 9.0cm - head font size is untouched, so 16:9 decks look airier: the same \begin{frame} content occupies less width Other keys in the class: 43 (default) · 32 · 54 · 149 · 1610 · 141 · 2013, or any number like 137. WHY MEASURES FROM AN ARTICLE DO NOT TRANSFER article at 10pt: \textwidth ≈ 6in = 15.2cm, margins ≈ 1in + \oddsidemargin beamer: 10.8cm of text on a 12.8cm page — no automatic two-column, no float placement, \linewidth is the frame body \columnwidth = 0.48\textwidth - \columnsep in columns so \includegraphics[width=\linewidth] is right in a column and wrong if you sized it against the paper instead Practical consequence: a figure you tuned in cm for an article must be re-tuned for a deck; size it as a fraction of \linewidth and both survive an aspect-ratio change. Check the geometry of a deck with the frame option [plain] to drop headline and footline while you measure.
    Where the paper, the margins and the body box of a frame come from, and why measures do not transfer from an article.

    The overlay time-map: specifications and the pause counter

    An overlay specification is a range expression over the pages of one frame: <2>, <2-4>, <-3>, <3->, <2,5>, <odd>, <all>. Absolute numbers count the frame's PDF pages, which means that adding a \pause earlier in the frame silently shifts every later number. That is the maintenance problem, and beamer's answer is the relative form.

    Write <+-> for "from here on", <+> for "on this one", and <+(1)> or <+(-2)> to offset. Behind them is the counter beamerpauses, which \pause increments and every overlay-aware environment steps through as it is encountered; a specification using + reads the counter at that point. Relative specs survive reordering, which is why decks that grow use them.

    The mode prefix qualifies a spec with an output mode: <all:2->, <beamer:3>, <handout:0>. Combined with \begin{frame}<handout:0> this is how you keep one source that projects in five slides and prints as one page — no second file, no copy-paste drift.

    You also control how not-yet-revealed material looks, globally: \setbeamercovered{invisible} (the default) shows nothing, \setbeamercovered{transparent=15} ghosts it at fifteen per cent opacity so the audience sees the shape of what is coming, and dynamic/highly dynamic fade the immediately-upcoming item differently from the rest. Set it once in the preamble; a transparent deck is often what people mean when they say the jumps look wrong.

    \underbrace{a_{0} + a_{1}x + a_{2}x^{2} + \cdots}_{\text{the generating function}}
    \underbrace{a_{0} + a_{1}x + a_{2}x^{2} + \cdots}_{\text{the generating function}}
    Overlay time map: which slide number shows which block, and how pause counters and relative specs line up ONE FRAME, FIVE PDF PAGES · THE “SLIDE” NUMBER IS THE COLUMN material 1 2 3 4 5 \only<2>{hint} \visible<3->{proof} \uncover<-2,4>{note} \begin{block}<+->{…} solid = drawn · hatched = typeset but covered, so the space is still reserved · hollow with \only = never even typeset on that slide THE THREE SPEC FORMS THAT DO MOST OF THE WORK <3> <2-4> <-2> <3-> <2,5> absolute: counted in PDF pages of the frame, so a frame that splits shifts every number <+-> <+(1)> <+(-2)> relative to the beamerpauses counter, which \pause and each overlay-aware env advance <all:2-> <handout:1> <beamer> mode-qualified: one deck, two outputs — projected overlays and a flat handout, from one source
    A five-overlay frame as five PDF pages: which material is drawn, which is covered, and which is never typeset at all.

    only, alt, visible, uncover, temporal, onslide — the real differences

    The dividing line is whether the material is typeset on the slides where it is not wanted. \only<2>{…} is not: on every other slide the tokens are discarded before typesetting, so nothing is measured and no space is left. That is what you want for a title that changes, and what makes text below it jump when the second overlay arrives.

    \visible<2->{…} and \uncover<2->{…} both typeset the content on every slide and reserve its space. The difference is the hiding mechanism: \visible draws with PDF-level invisibility, so the glyphs are simply not there and cannot be selected; \uncover hands the material to the covering machinery configured by \setbeamercovered, which is where transparent comes from. Use \visible when you want a hole in the layout filled invisibly and no ghost; use \uncover when the ghost is the point.

    \alt<2>{this}{that} chooses one branch and, like \only, reserves no space for the loser; its environment form is altenv with four arguments (start, before, after, end). \temporal<2>{before}{during}{after} is different in kind: all three parts are always typeset and measured, and only the styling changes. That is why \temporal is the right tool for "highlight the current item, dim the previous ones" and the wrong tool for inserting a line of text.

    \onslide is the odd one: it takes no braced argument, it switches a covering state for everything that follows, and its starred form is literally \only while \onslide+ behaves like \visible. Most "why did the rest of my frame disappear" bugs are \onslide used where \uncover was meant. For whole environments there are onlyenv, uncoverenv and the general actionenv, plus alertenv and structureenv for colouring a region.

    \begin{aligned} f(x) &= x^{2}+1 \\ f'(x) &= 2x \end{aligned}
    \begin{aligned} f(x) &= x^{2}+1 \\ f'(x) &= 2x \end{aligned}
    Comparison of only, alt, visible, uncover, temporal and onslide: is the material typeset, is space reserved, what does it hide behind PICK THE COMMAND BY WHAT YOU NEED THE LAYOUT TO DO command typeset off-spec? space reserved? selectable in the PDF? use it for \only<2>{…} discarded before typesetting no no no swapping one thing for another: titles, labels \alt<2>{a}{b} both read, one chosen one no chosen two different renderings, e.g. compact vs full \visible<2->{…} drawn with PDF invisibility yes yes no nothing at all appears; safe on any background \uncover<2->{…} covered per \setbeamercovered yes yes maybe default is invisible; add transparent=15 to ghost it \temporal<2>{before}{now}{after} all three always typeset yes yes styled colour or weight changes, never for inserting text \onslide<2-> … rest of frame switches a mode, takes no braced group yes yes covered styling whole regions; \onslide* = \only, \onslide+ = \visible The two mistakes this table exists to prevent: \only inside a frame that must keep its height (the block jumps), and \onslide used where a braced group was intended — \onslide does not take a braced argument, it changes the covering state for everything that follows. Environment equivalents when the material is a whole block: onlyenv (like \only), uncoverenv (like \uncover), actionenv for anything that needs an overlay spec.
    Six commands, one question each: is it typeset off-spec, is space reserved, and what does it hide behind.

    Overlay specifications on environments, blocks and frames

    Beamer re-declares most of the environments you know so they accept a trailing specification: \begin{block}<2->{Title}, alertblock, exampleblock, theorem-style environments, quote, verse, description and list environments all take <spec> after the name. Underneath, an overlay-aware environment is built on \newenvironment<>, which is a LaTeX-level feature: the <> says "read an optional angle-bracket spec and expose it as #1", and the environment then runs the right action per slide.

    Blocks with per-instance colour and title come from \setbeamertemplate{blocks}[rounded][shadow=true] and the colour hooks block title/block body; the alert colour is \setbeamercolor{alerted text}{fg=…}, and \alert{…} and \structure{…} are the in-text wrappers that consult those colours rather than hard-coding them.

    A whole frame can carry a specification too — \begin{frame}<1> — which is how you build a slide that exists only in the handout or only at a certain point. Combine that with frame labels: \begin{frame}[label{key}] defines a name you can re-show later with \againframe<2>{key}, optionally with \setbeamertemplate{frametitle continuation}[from second] to control the "(next part)" suffix. It is the standard trick for a proof shown in pieces early and recapitulated at the end.

    Frames also number themselves, and sometimes should not: [noframenumbering] keeps a frame out of the footer count (useful for the title page and the section recaps generated by \AtBeginSection), [plain] removes headline and footline, and [environment=…] replaces the environment that wraps the frame body, which is the hook beamerarticle and custom themes use when one source must also produce a paper.

    \frac{1}{2} \le \int_{0}^{1} \frac{\mathrm{d}x}{1+x^{2}} \le 1
    \frac{1}{2} \le \int_{0}^{1} \frac{\mathrm{d}x}{1+x^{2}} \le 1

    Fragile frames: verbatim, listings, TikZ and catcodes

    A normal frame's contents are read as a macro argument before being typeset. Anything that depends on catcodes — \verb, the verbatim environment, lstlisting from the listings package, a \path<2-> in a TikZ picture that itself uses overlay specs, or code with #, _ or % in it — needs the frame option [fragile]. With it, beamer writes the body to a temporary file and reads it back at typesetting time with the catcode regime intact; without it, you get the classic Paragraph ended before \beamer@... was complete or a garbled listing.

    The cost is real, so it is worth knowing what you pay for: a fragile frame cannot be used where its body must be an argument, some nested constructs stop working, and the error messages get less helpful. Keep code samples in their own frames rather than making a whole deck fragile. The related option [containsverbatim] is narrower and is what \verb alone needs in some themes.

    TikZ and pgfplots deserve their own paragraph. Simple pictures in a frame work fine; pictures that use overlay specifications on their own paths (\node<2->) must be in a fragile frame, and the <> form of \newcommand that beamer installs means a TikZ \foreach with #1 in the body must double its hashes. pgfplots plots are expensive: each redraw is real computation, so in a deck with several plots use \usepgfplotslibrary{externalize}-style caching, or export once to PDF and \includegraphics it. This is the single largest build-time lever in a beamer source.

    Symptom-checking in order for "my frame is broken and I do not know why": add [fragile], then remove overlays, then remove the block environments, then remove the graphic. Frame-level minimisation is faster than line-level, because a frame is the unit the class parses.

    % show-me-the-notes.tex
    % presenting:  xelatex show-me-the-notes.tex
    % handout:     xelatex -jobname=handout "\PassOptionsToClass{handout}{beamer}\input{show-me-the-notes}"
    \documentclass{beamer}
    \usetheme{Warsaw}
    \usepackage{mwe}   % example-image-a / -b, so this file compiles as it stands
    
    \setbeameroption{show notes on second screen=right}   % two-page spread per slide
    % \setbeameroption{show only notes}                   % speaker script as a PDF
    % \setbeameroption{hide notes}
    
    \setbeamertemplate{note page}[plain]
    \setbeamerfont{note page}{size=\small}
    
    \begin{document}
    
    \begin{frame}{Sizing graphics against the frame, not the paper}
      \begin{columns}[T]
        \begin{column}{0.45\textwidth}
          \includegraphics[width=\linewidth, height=4.5cm, keepaspectratio]{example-image-a}
    
          \smallskip
          \footnotesize sized against \textbackslash linewidth, so it follows the column
        \end{column}
        \begin{column}{0.5\textwidth}
          \begin{itemize}
            \item \texttt{width=\textbackslash linewidth} follows the column
            \item \texttt{width=0.48\textbackslash textwidth} follows the frame
            \item never \texttt{scale}: it resizes the font too
          \end{itemize}
        \end{column}
      \end{columns}
      \note[item]{First point: the aspect ratio changed the numbers.}
      \note{Second point: \texttt{keepaspectratio} avoids the stretched look.}
    \end{frame}
    
    \begin{frame}<handout:0>{Projector-only aside}
      \only<1>{\includegraphics[width=6cm]{example-image-b}}%
      \only<2->{\includegraphics[width=6cm]{example-image-a}}
    \end{frame}
    
    \end{document}

    Structure: title, sections, contents, notes, appendix

    The title frame is \titlepage inside a frame, usually \begin{frame}[plain]\titlepage\end{frame}, and the metadata comes from \title, \subtitle, \author, \institute, \date and \titlegraphic. Each has an optional short form — \title[Short]{Long} — and the short form is what the headline and footline print, so an unstated short title is a long title repeated in every header.

    Section pages come from \section plus the idiom \AtBeginSection[]{\begin{frame}<beamer>[plain, noframenumbering]\tableofcontents[currentsection]\end{frame}}. \tableofcontents accepts currentsection, hideothersubsections, pausesections and hideallsubsections; pausesections turns one contents frame into several, which is how a deck navigates itself back to the outline without a click-through of identical pages.

    Speaker notes are \note{…}, optionally with an overlay spec and an [item] label, and they are invisible in the PDF unless you ask: \setbeameroption{show notes} appends a note page after each slide, show notes on second screen=right produces a two-page spread designed for a laptop presentation view, and show only notes prints just the script. Template and font: \setbeamertemplate{note page}[plain], \setbeamerfont{note page}{size=\small}. Handing out a flat version of the deck is the handout class option, which collapses overlays to one page each and drops notes.

    The back half of a deck is \appendix followed by backup frames, and it is genuinely worth building: a question that a hidden slide answers is the highest-yield moment of a talk. Cited work goes in a final \begin{frame}[allowframebreaks] holding a thebibliography or \printbibliography, with \setbeamertemplate{bibliography item}[text] if the theme insists on drawing a small icon per entry.

    Themes, colours and templates — and where customising stops paying

    Themes are four independent families: outer (headline, footline, sidebar, navigation), inner (margins, block shapes, itemize symbols), colour and font. \usetheme{Madrid} is a bundle of those choices; you can mix at any granularity with \usecolortheme{whale}, \usefonttheme{serif} or \useoutertheme{infolines}. The list of what is installed is short and worth browsing once: texdoc beamer documents each, and metropolis (theme m) is the modern flat alternative people reach for when the default gradients look dated.

    Below the theme level, three commands do nearly everything. \setbeamercolor{normal text}{fg=…, bg=…} — where changing bg is a serious decision, because overlays and blocks assume a solid background. \setbeamertemplate{itemize items}[square], {navigation symbols}{}, {frametitle}{…} for structural pieces. \setbeamerfont{frametitle}{size=\large, series=\bfseries} for typography. And \addtobeamertemplate{footline}{before}{after} when you want to keep the theme's footline and append a page counter.

    A specific trap worth naming: \usefonttheme{professionalfonts} is mandatory when you load unicode-math, a custom \setmainfont, or the newtx/mathpazo families. Without it beamer keeps its own math font choices and your font appears in prose but not in equations, or the frame titles fall back to Computer Modern at odd sizes. Load the font package first, then the font theme.

    Geometry-level customisation uses \setbeamersize{text margin left=1.2cm, text margin right=1.2cm}, which is the honest way to buy back horizontal space rather than shrinking the font. Everything else about layout should be done by sizing material as a fraction of \linewidth or \textheight: those numbers change with the aspect ratio, and a deck that survives a 4:3-to-16:9 switch without edits is one that never hard-coded centimetres.

    \zeta(s) = \prod_{p\ \mathrm{prime}} \frac{1}{1 - p^{-s}} \qquad \Re(s) > 1
    \zeta(s) = \prod_{p\ \mathrm{prime}} \frac{1}{1 - p^{-s}} \qquad \Re(s) > 1
    \documentclass{beamer}
    \usetheme{Berlin}
    \usepackage{amsmath}
    
    \begin{document}
    
    \begin{frame}{only / alt / visible / uncover / temporal}
      \only<1>{\textbf{only}: the other slides do not even contain this text.}\\
      \only<2>{\textbf{only} again --- watch the line below jump up.}\\[6pt]
    
      \alt<3>{\textbf{alt}: this branch is typeset}{\textbf{alt}: this one is not}\\[6pt]
    
      \visible<4->{\textbf{visible}: glyphs are drawn invisibly, no copy-paste.}\\[6pt]
    
      \uncover<5->{\textbf{uncover}: covered per \textbackslash setbeamercovered.}\\[6pt]
    
      \temporal<6>{\textcolor{gray}{\textbf{temporal}: before}}
                  {\textcolor{red}{\textbf{temporal}: during}}
                  {\textbf{temporal}: after}
    \end{frame}
    
    \begin{frame}<beamer:0>{This frame exists only in the handout}
      A frame you project nothing of.
    \end{frame}
    
    \begin{frame}<handout:0>{Hidden in the handout, shown when presenting}
      \begin{uncoverenv}<2->
        An environment form: everything inside is subject to the spec.
      \end{uncoverenv}
      \begin{onlyenv}<3>
        Replaced wholesale on other slides, so no space is reserved.
      \end{onlyenv}
    \end{frame}
    
    \begin{frame}[label=slowproof]{A proof in four steps}
      \begin{align*}
        a_{n} &= \frac{1}{n}\sum_{k=1}^{n} x_k \\
        \intertext{hence}
        |a_{n}| &\le \frac{1}{n}\sum_{k=1}^{n} |x_k|
      \end{align*}
      \pause
      and the last line uses boundedness of $(x_k)$.
    \end{frame}
    
    \begin{frame}{Recap}
      Re-showing a labelled frame, with only its second overlay visible:
    \end{frame}
    
    \againframe<2>{slowproof}
    
    \end{document}

    Lesson cheat sheet

    One key line of code from each section — jump to it or copy it straight from here.

    Section Key code
    \underbrace{a_{0} + a_{1}x + a_{2}x^{2} + \cdots}_{\text{the generating function}}
    \begin{aligned} f(x) &= x^{2}+1 \\ f'(x) &= 2x \end{aligned}
    \frac{1}{2} \le \int_{0}^{1} \frac{\mathrm{d}x}{1+x^{2}} \le 1
    \documentclass{beamer}

    Common mistakes

    • A \verb, lstlisting, verbatim or overlay-aware TikZ picture in a frame without [fragile]. Add the option; the body is then re-read with sane catcodes instead of being grabbed as an argument.
    • Absolute overlay numbers everywhere, so inserting one \pause early in a frame breaks every later <4>. Use <+-> and <+(1)> so specs follow the pause counter.
    • Using \onslide<2> when \uncover<2>{…} was meant: \onslide takes no braced group, so it silently applies to the rest of the frame.
    • Sizing images in centimetres copied from an article. The frame body is 10.8cm wide at the default 4:3 and 14cm at 16:9; width=\linewidth survives an aspect-ratio change, a fixed length does not.
    • Relying on [shrink] to fit a full frame. It shrinks the box, not your design; split the frame or move material to a backup slide.
    • Overlay specifications inside an [allowframebreaks] frame: the split and the overlay machinery cannot agree, and beamer warns or drops the spec.
    • Loading unicode-math or a custom text font without \usefonttheme{professionalfonts}, then debugging why the equations still use beamer's fonts.
    • Forgetting the short forms \title[short]{long} and \author[short]{long}, which puts the full title in the header of every frame.

    Questions about this lesson

    What is the difference between only, uncover and visible in beamer?
    only discards the material on non-matching slides, so nothing is typeset and no space is reserved, which makes the layout jump. uncover and visible both typeset the material and reserve its space; visible makes the glyphs genuinely invisible in the PDF, while uncover hides it through beamer's covering mechanism, which \setbeamercovered configures — invisible by default, transparent=NN to ghost it. Rule of thumb: only for swapping one thing for another, uncover or visible when the rest of the frame must not move.
    Why does my beamer frame say Paragraph ended before something was complete?
    Almost always a frame whose contents need verbatim-like catcodes — \verb, a verbatim or lstlisting environment, a TikZ path with an overlay spec, or code containing #, _ or %. Beamer reads a normal frame body as an argument, so add the frame option [fragile], which writes the body to a temporary file and re-reads it with sane catcodes. If a blank line is genuinely stray, deleting it is the other fix.
    How do I make beamer slides 16 by 9?
    Pass the aspect-ratio option to the class: \documentclass[aspectratio=169]{beamer} gives a 16.00cm by 9.00cm canvas, and \textwidth becomes 14cm instead of the default 10.8cm. Other named values are 43 (default), 32, 54, 149, 1610, 141 and 2013, and any bare number is treated as a ratio. After switching, re-check anything you sized with fixed lengths or font sizes, since the canvas grew but the type did not.
    How do I show speaker notes in beamer?
    Put the text in \note{...} inside a frame, then choose a viewing mode in the preamble: \setbeameroption{show notes} appends a notes page after each slide, show notes on second screen=right produces a two-page spread for a laptop presenter view, and show only notes prints just the script. Notes are omitted entirely when the class is compiled with the handout option, so one source serves projection and printing.
    Why does my beamer table of contents show all sections on every section slide?
    Because the plain \tableofcontents call prints everything. Use the optional keys: \tableofcontents[currentsection] highlights the section you are in, hideothersubsections and hideallsubsections trim the detail, and pausesections reveals one section per overlay. Put the whole frame inside \AtBeginSection[]{...} so it appears before each section, and add [plain, noframenumbering] if you do not want it counted in the footer.
    Can I use beamer without a presentation theme?
    Yes, and it is often the right starting point for a corporate layout: \documentclass{beamer} alone, then \usetheme{default}, plus \setbeamercolor, \setbeamertemplate and \setbeamerfont for the parts you must match. Themes are just presets of those three commands, so a custom look means overriding them, not copying a theme file. Load \usefonttheme{professionalfonts} as soon as you bring your own text or math font.

    Live playground: edit the LaTeX, see it render

    The preview updates as you type — break it on purpose to see how errors look.

    KaTeX error
    Try an example

    Keep reading

    Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.