How to create presentations with Beamer

Beamer brings LaTeX's powerful typesetting features and ecosystem to creating slides.
162 readers like this.
Business presentation

Vector Open Stock. CC BY-SA 3.0.

Beamer is a LaTeX package for generating presentation slide decks. One of its nicest features is that it can take advantage of LaTeX's powerful typesetting system and all the other packages in its ecosystem. For example, I often use LaTeX's listings package in Beamer presentations that include code.

Starting a presentation

To begin a Beamer document, enter:


As you would with any other LaTeX document, add any packages you want to use. For example, to use the listings package, enter:


Place all content inside the document environment:


Beamer documents are usually a sequence of frame environments. Frames that contain code should be marked fragile:


Begin your frames with a title:

\frametitle{Function to Do Stuff}

Testing your code before you present it

One of the worst feelings in the world is giving a talk and realizing, as you walk through the code, that there is a glaring bug in it—maybe a misspelled keyword or an unclosed brace.

The solution is to test code that is presented. In most presentation environments, this means creating a separate file, writing tests, then copying and pasting.

However, with Beamer, there is a better way. Imagine you have a file named that contains code. You can write tests for the code in a second file, which you call, and can exercise it with, say, pytest. However, most of the lines in lack pedagogic value, like defining helper functions.

To simplify things for your audience, you can import just the lines you want to talk about into the frame in your presentation :


Since you will be talking through those lines (from 8 to 15), you don't need any other content on the slide. Close the frame:


On the next slide, you want to show a usage example for the do_stuff() function you just presented:

\frametitle{Calling Function to Do Stuff}

You use the same file, but this time you show the lines that call the function. Finally, close the document:


Assuming you have an appropriate Python file in, this will produce a short two-slide presentation.

Beamer also supports necessary features such as progressive revelation, showing only one bullet at a time to prevent the audience from being distracted by reading ahead.": \pause inside a list will divide bullets into pages:

\item This will show up on the first slide. \pause
\item This will show up on the
      second slide, as well as the preceding point. \pause
\item Finally, on the third slide,
       all three bullets will show up.

Creating handouts

My favorite feature in Beamer is that you can set it to ignore everything outside a frame with \documentclass[ignorenonframetext]{beamer}. When I prepare a presentation, I leave off the top (where the document class is declared) and auto-generate two versions of it: one with Beamer that ignores all text outside any frame, which I use for my presentation, and one with a header like:


which generates a handout—a PDF that has all the frames and all the text between them.

When a conference organizer asks me to publish my slides, I include the original slide deck as a reference, but the main thing I like people to have is the handout, which has all the explanatory text that I don't want to include on the slide deck itself.

When creating presentation slides, people often wonder whether it's better to optimize their materials for the presentation or for people who want to read them afterward. Fortunately, Beamer provides the best of both worlds.

Moshe sitting down, head slightly to the side. His t-shirt has Guardians of the Galaxy silhoutes against a background of sound visualization bars.
Moshe has been involved in the Linux community since 1998, helping in Linux "installation parties". He has been programming Python since 1999, and has contributed to the core Python interpreter. Moshe has been a DevOps/SRE since before those terms existed, caring deeply about software reliability, build reproducibility and other such things.


Any examples of slides (and sources) created in this manner?

You can find a collection of examples at this website. The examples include the LaTeX source files and HTML and PDF output.

In reply to by John Carter (not verified)

For some similar reasons I prefer Scribus for generating slides for a talk. You have ultimate control of the layout and displaying with a PDF viewer is quite easy. You can include a wide variety of images in the content, including vector graphics and incorporate PDFs in your page.

This article made me feel like an old-timer. I have been using beamer a LOT in grad school. It made technical presentations so much easier to create. But I did not know about an option of importing just code fragments from an external source file. Thanks!

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.