Jeromy Anglim's Blog: Psychology and Statistics


Wednesday, August 25, 2010

Getting Started with Beamer: Tips and Tricks for LaTeX Presentations

This post provides a guide to getting started with Beamer, a popular LaTeX package for preparing slide presentations. The post: (a) Lists some of the benefits of Beamer in comparison to PowerPoint; (b) Links to tutorials and suggestions for learning Beamer for both people who do and do not know LaTeX; (c) Documents problems that I encountered when learning to use Beamer and the solutions that I developed to overcome them.

Overview Of Beamer

Benefits of Beamer

In contrast to Microsoft PowerPoint, the following are some of the benefits of Beamer:
  • Outputs to PDF which allows for consistent appearance across versions and Operating systems
  • Free as in no cost and free as in the ability to view and modify the source code
  • Simple generation of slide navigation tools
  • Robust incorporation of mathematical formulas
  • Text based format enables programmatic incorporation of slides and use of text manipulation tools to alter presentation
  • Easier to create different versions of slides for handouts, articles, and the main presentation
  • As with LaTeX in general, it is easier to create reproducible research
  • Encourages good practice in slide construction and formatting (e.g., consistent formatting; useful defaults; strong support for navigation; encourages a focus on content rather than fancy effects; etc.)
  • Sequencing and highlighting of presentation text is easy (i.e., overlays)

Getting Started

The starting point for learning Beamer depends on whether you already know LaTeX.

If you don't know LaTeX:

Then you'll want to learn about LaTeX before getting started with Beamer. You'll need:
(a) A text editor. I currently use WinEdt 6.0, which integrates with MikTeX particularly well. TeXnicCenter also integrates with MikTeX well. See this discussion on StackOverflow regarding good LaTeX editors.
(b) A LaTeX distribution. I use MikTeX. MikTeX appears to be a popular option on Windows. It does a good job of automatically downloading packages, such as beamer.

Then spend a couple of weeks learning LaTeX by reading materials about LaTeX and applying the ideas to a document you are currently working on. There's heaps of good materials online, such as: If you have the money or a good library, its worth reading a few books.

If you already know LaTeX:

If you already know LaTeX but you don't know Beamer, I'd suggest the following steps.
1. Get Started:
This tutorial on Math-Linux shows a very basic beamer presentation. Run the code in your text editor to ensure your installation is working. Get a flavour for the essential elements of a Beamer document.
2. Get Oriented:
3. Learn the detail
The Beamer user guide is excellent. It is over 200 pages. It's worth reading in its entirety.
More tips, if you want them

General Reflections

I've used the transition to Beamer to reflect on my slide creation strategies.
  • Use sections and subsections wisely. Think of the document in terms of a hierarchical structure.
  • Incorporate Tables of contents to show the outline of the talk. In long talks remind the audience of where you are in the structure.
  • In longer talks, use the visual section display tools
  • Use slide text to support the talk, not supplement the talk. Only include extended passages of text, where the exact wording is particularly important, such as for quotes and definitions. If extended passages of text are important enough to include, they should generally be read out verbatim, so that the audience is not conflicted between whether to listen to the speaker's words or read the slides. Most of the time, extended passages of text should be avoided. The words of the talk should extend the text displayed on the screen.
  • If a more comprehensive handout is required such as for future reference or for people who did not attend the talk, a separate document should be prepared. Beamer makes this relatively easy with handout and article modes.
  • Prefer more slides to fewer slides with too much information. If there are a large number of points on a slide, the slide should be split into multiple slides.

Challenges Resolved

The following reflects a few of the problems that I encountered when first learning Beamer and the solutions I adopted. Many of the solutions were generated by reading the Beamer User Guide.

1. Fitting text on a slide

Problem: PowerPoint automatically adjusts the size of text to fit on a slide. What is the Beamer approach to this problem?

Solution: Users of Beamer and LaTeX actively discourage such ad hoc adjustment of font sizes. In such situations the slide should be restructured. However, shrink=5 can be added as a frame option (see UMBC). Alternatively, the allowframebreaks is an option of the frame environment. It can be used to extend text over multiple slides.

2. Handouts with only a subset of slides

Problem: When I create presentations, I often include slides that I don't want included in the handout. For example, I may wish to include a series of photos in the presentation, but leave them out of the handout.

Solution: See nabble for a discussion. I add handout:0 to the frame as follows:
\begin{frame}<handout:0>{Title of Frame}
To print handouts the document class is changed as follows:
\documentclass[handout, t]{beamer}

A second option is to add a line in the preamble like this:
\includeonlyframes{handout}
Then each frame that is to be included in this version should have the additional label.
\begin{frame}[label=handout]

3. Full Screen Images

Problem: How do you create slides with full screen images?

Solution: It is useful to know that the default frame size is 128mm (width) by 96mm (height). One solution is suggested on this news group. The beamer user guide also mentions the textpos package as a tool for positioning figures absolutely.

The following strategy worked, but not when I had \mode* in operation.
{
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{figure}}
\begin{frame}[plain]
\end{frame}
}


The following seems to work when I have \mode* operating in the document.
\mode<all>
{
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{figure}}
\begin{frame}[plain]
\end{frame}
}
\mode<all>{\usebackgroundtemplate{}}
\mode*

4. Incorporating Notes

Problem: In general, when I prepare a presentation, I like to write out the main points that I want to make. When it comes time to giving the presentation, I don't read the notes, but the act of writing the notes, ensures that I have thought about the points that I want to make. If I need to give the presentation a second time, I'll read over the notes again. In some settings, I'll make a copy of the presentation available that includes both the slides and the notes. Thus, in Beamer I was looking for a good system that (a) enabled the writing of notes in an around the latex source for each slide (b) enabled easy toggling between PDF versions of the presentation with and without notes.

Solutions:
A. Beamer does allow for the \notes command.

B. However, my preferred solution is to type normal sentences after each slide; i.e., after \end{frame}. I then add \mode* just after \begin{document}. In general this means that text outside frames is not displayed in the presentation. The benefit of this approach are that (a) these notes can easily be converted into a written text using the article mode; and (b) text can be written in a natural way without the need to enclose it in a particular environment or command. More information about \mode* and \mode is available in the beamer user guide. The user guide also has advice (21.2.2 Workflow) on how to manage the production of an article and a presentation version of a document.

5. Hyperlinks within the document

Problem: How do you set up buttons and links from one slide to another?

Solution:
  • Section 11 of the Beamer user guide has a section on Adding Hyperlinks and Buttons.
  • UMBC has a simple example of using hyperlink buttons.

6. Removing Superfluous materials

Problem: Many of the standard templates include many extra lines above and below the slide that reduce the space available for slide content. How should this be dealt with?

Solution: The advice on most beamer-related websites regarding navigation is as follow. If the presentation is short and simple, don't include navigation. If the presentation is long or complex, include navigation. The loss of slide-space to navigational elements is worth it. Material can be restructured to use more slides.

Similarly, the footlines are typically used to put things like presenter's name, institutional affiliation, title, page number, and so on. The general advice on beamer-related websites is that if your audience knows all this information already (e.g., lecture in a university subject), then don't included it. If your audience doesn't know this information (e.g., conference presentation) include it.

It is possible to temporarily remove remove headlines, footlines and sidebars by using the [plain] option in the frame environment. This is particularly useful for slides that show a single large image.

The following code in the preamble can be used in order to create a sparse style:
\usetheme{default} 

7. Forward and Inverse Search with PDF

Problem: I'd previously been using latex and a DVI viewer for compiling documents. I decided to make the transition to pdflatex. pdflatex makes it easier to work with graphics supporting png, jpg, and pdf, as opposed to latex which supports eps. Unfortunately, Adobe Acrobat does not support forward and inverse search which makes it a lot easier to edit latex source.

Solution: I downloaded and installed Sumatra PDF. Configuring was simple in WinEdt 6.0.
Options - Execution Modes - PDF Viewier - Sumatra PDF
There is further discussion here.

In WinEdt the default keys are: Ctrl+Shift+R to show PDF, and Shift+F8 to do forward search. Double clicking in the PDF goes to the latex source.

8. Improving the WinEdt 6.0 Tree View

Problem: WinEdt 6.0 has a tree view which by default shows various aspects of the structure of latex documents, such as sections and subsections. I wanted to be able to see frames underneath sections and subsections. This would allow me to navigate more easily to particular slides. It would also help in seeing where I was in the hierarchical structure of the presentation.

Solution: I added the following code to tree.ini. I simply adapted it from an existing example. It works, but I am not sure what all the lines of code are doing. It also does not work with some less common frame declarations.
  ITEM="\begin{frame}{?}"
    MODE="TeX"
    CASE_SENSITIVE=1
    BEGINNING_OF_LINE_ONLY=1
    CURRENT_DOCUMENT_ONLY=1
    ALL_OPENED_DOCUMENTS=0
    COMPLETE_PROJECT_TREE=1
    ICON="Paragraph"
    LEVEL=26
    CAPTION="%?"
    BALANCED="{}\"
    MAX_LINE_SPAN=3
    ON_CTRL_CLICK="GlobalMark;TreeTrack(2);"
    ON_CTRL_DBL_CLICK="Relax;"
    ON_CLICK="TreeTrack(2,1);"
    ON_DBL_CLICK="TreeTrack(2,2);"
    ACTION="Find"
      IMAGE="Find"
      MACRO="TreeTrack(2);"
    SUBSTITUTION="\label{*}"
      SUB_FIND="\\label\{*\}"
      SUB_REPLACE=""
      SUB_REG_EX=1
      SUB_CASE_SENSITIVE=1
    SUBSTITUTION="  "
      SUB_FIND=" +{ }"
      SUB_REPLACE=" "
      SUB_REG_EX=1
      SUB_CASE_SENSITIVE=1
    SUBSTITUTION="\ldots"
      SUB_FIND="\ldots"
      SUB_REPLACE="..."
      SUB_REG_EX=0
      SUB_CASE_SENSITIVE=1

9. Hyperlink Navigation within a Presentation

Problem: How can hyperlinks be included which can be clicked in order to navigate between slides. Solution: The beamer user guide discusses this. Matthias Pospiech presents a few examples of using buttons and hyperlinks. Go to the page and search for "hyperlink".

A simple option is to add a label to the target frame. E.g.,
\begin{frame}[label=thetargetlabel]
...
Then add within the linking frame
\hyperlink{thetargetlabel}{\beamergotobutton{Button Text}}
Then press Alt+Left to navigate back to the linking frame if viewing the slide show in Adobe Acrobat.

10.Creating handouts

Problem: Handouts are typically supplied with multiple slides per page. How is this effect achieved in Beamer?

Solution:
A. pdfnup is meant to be well suited to the task of placing n, pdf pages up onto one page.

B. I'm currently using the pgfpages package to do the job. I quite like the results that I get from four per page (i.e., 2 by 2) in landscape mode using the code below.
\mode<handout>{
\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[a4paper, border shrink=5mm, landscape]
}
The code
\mode<handout>{...}
requires the documentclass to have the handout option to be specified like this: \documentclass[handout, t]{beamer}

11. Minimising Typing

Problem: The markup for beamer is quite verbose. All the frame, block, columns, and itemize environments and the need to add item to the start of each dot point leads to a lot of non-content related typing.

Solutions
I received some helpful suggestions when I asked the question about minimising typing on tex.stackexchange.com.

A. There are several shorthand notations to make creating beamer presentations simpler. However, I'm reluctant to adopt these approaches. Using non-standard notation often introduces compatibility issues.

B. I have also set up template text of the most common types of slides. I place these in a separate file, which I can copy and paste into the main presentation file as required. I'm considering using some form of code snippet system. I present this template in a separate post.

12. Preventing Beamer markup from interfering with thinking

Problem: Beamer formatting tags are fairly verbose. For example, you have to remember to open and close environments and for each dot point its necessary to write "\item". Thus, producing a slide involves a fair amount of typing. Similarly, modifying a slide also takes time. When the content of the slide is still being refined, prematurely entering formatting can be a waste of time. In contrast to LaTeX documents, the markup to text ratio in Beamer presentations is particularly high. I found that writing Beamer markup often interfered with the content creation process.

Solution:
A. With practice, the markup becomes more natural. In addition, there are tricks for using slide templates to speed up the process of entering markup.

B. There are also various wiki-like markup languages which aim to make the markup less verbose.

C. Initially I found it useful to use my own loose markup style when writing the draft of the presentation. My process involved entering the details of the slide text on a first draft and then going over the slides in a second iteration to put in the markup. My basic markup looked like this:
\section{This is the first section}
* Slide 1 Title text
- point 1 on slide 1
- point 2 on slide 1

* Slide 2 Title text
% insert someImageFileName


D. In general over time I've found that typing basic beamer commands becomes a lot quicker and less distracting with practice. I've also found that I do a fair amount of initial brainstorming of the structure and content of a presentation in a separate outlining tool such as Outline View in Word.

13. Resolving Beamer Error Messages

Problem: Beamer error messages can be particularly mysterious. What are common error messages? What strategies speed up diagnosis and resolution of error messages?

Solution:
Common errors include:
  • Forgetting to include the end environment. e.g., \end{block}
  • Problems with braces }: e.g., forgetting to include a brace; typing the wrong character, such as a parenthesis; problems with nested braces, etc.
  • Forgetting to add at least one \item in an itemize environment
  • Forgetting to add a title to a block environment
  • Typographical mistakes in common command names (e.g., ietm or iteM instead of item
  • Putting begin where end should be placed and vice versa.
  • Forgetting to escape (i.e., "\") special characters such as the ampersand, dollar sign, and percentage sign particularly when pasting text from another source
General strategies for debugging:
  • In some instances, the error message will indicate the text that is related to the error.
  • The LaTeX compiling information often indicates the number of the slide at which an error occurred. e.g., you will see [1][2][3]...
  • In other situations progressively move the \end{document} command around the document. The document will only compile up to that point. This should isolate the slide where the error is occurring.
  • Frequently compile, especially when first learning, to minimise the possible error locations.
  • Once the probable frame has been identified, look for common errors in the frame as mentioned above.
  • Use an editor that flags common errors such as non-matching environments or mistyped command names