Book Image

LaTeX Cookbook

By : Stefan Kottwitz
Book Image

LaTeX Cookbook

By: Stefan Kottwitz

Overview of this book

LaTeX is a high-quality typesetting software and is very popular, especially among scientists. Its programming language gives you full control over every aspect of your documents, no matter how complex they are. LaTeX's huge amount of customizable templates and supporting packages cover most aspects of writing with embedded typographic expertise. With this book you will learn to leverage the capabilities of the latest document classes and explore the functionalities of the newest packages. The book starts with examples of common document types. It provides you with samples for tuning text design, using fonts, embedding images, and creating legible tables. Common document parts such as the bibliography, glossary, and index are covered, with LaTeX's modern approach.You will learn how to create excellent graphics directly within LaTeX, including diagrams and plots quickly and easily. Finally, you will discover how to use the new engines XeTeX and LuaTeX for advanced programming and calculating with LaTeX. The example-driven approach of this book is sure to increase your productivity.
Table of Contents (19 chapters)
LaTeX Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a presentation


At a conference or at a seminar, speakers often use a projector or a screen for presenting written information in addition to what they are addressing. Such a presentation document requires a specific kind of layout and features.

In our recipe, we will use the beamer class, which has been designed specifically for this purpose. It provides the following features:

  • A typical landscape slide format, here 128 mm x 96 mm

  • Structured frames with dynamic information; for example, about sectioning

  • Support for overlays and transition effects

  • Predesigned themes for easily choosing the look

  • A smart interface for customizing

How to do it...

We will start off with a sample presentation document, which we can extend. Follow the given steps:

  1. Start with the beamer document class:

    \documentclass{beamer}
  2. Choose a theme. Here, we take the theme called Warsaw:

    \usetheme{Warsaw}
  3. Begin the document:

    \begin{document}
  4. Provide a title, subtitle, the names of the author and the institute, and a date:

    \title{Talk on the Subject}
    \subtitle{What this is about}
    \author{Author Name}
    \institute{University of X}
    \date{June 24, 2015}
  5. Make a slide using the frame environment. The first one will contain the title page:

    \begin{frame}
      \titlepage
    \end{frame}
  6. Make a frame for the table of contents, with the title Outline. Add the option pausesections, so the table of contents will be shown stepwise, section by section:

    \begin{frame}{Outline}
      \tableofcontents[pausesections]
    \end{frame}
  7. Start a section and a subsection within it:

    \section{Introduction}
    \subsection{A subsection}
  8. All visible content goes into the frame environment, including lists, which are visually better than normal text in a presentation:

    \begin{frame}{Very Informative Title}
      \begin{itemize}
        \item First thing to say.
        \item There is more.
        \item Another short point.
      \end{itemize}
    \end{frame}
  9. This frame will show an emphasized block with the title:

    \begin{frame}{Another Title With Uppercased Words}
      Text
      \begin{alertblock}{A highlighted block}
        Some important information put into a block.
      \end{alertblock}
    \end{frame}
  10. Add another subsection with a frame with a titled block. Also, add a new section with a slide containing a list. We have highlighted some words by using the \alert command. Finally, end the document:

    \subsection{Another subsection}
    \begin{frame}{Informative Title}
      \begin{exampleblock}{An example}
        An example within a block.
      \end{exampleblock}
      Explanation follows.
    \end{frame}
    \section{Summary}
    \begin{frame}{Summary}
      \begin{itemize}
        \item Our \alert{main point}
        \item The \alert{second main point}
      \end{itemize}
      \vfill
      \begin{block}{Outlook}
        Further ideas here.
      \end{block}
    \end{frame}
    \end{document}
  11. Compile, and take a look at the slides we have produced:

  12. Adjust the title, name of the author, and date.

  13. Edit the text in the frames. Add your own frames with titles and text. Use the components you found here, such as bulleted lists and boxes.

How it works...

We loaded the beamer class and chose the theme with the name Warsaw. You can easily replace it with another theme's name, compile it, and cycle through the themes until you find the best one for your occasion. By default, the following themes are installed:

  • AnnArbor

  • Antibes

  • Bergen

  • Berkeley

  • Berlin

  • Boadilla

  • boxes

  • CambridgeUS

  • Copenhagen

  • Darmstadt

  • default

  • Dresden

  • EastLansing

  • Frankfurt

  • Goettingen

  • Hannover

  • Ilmenau

  • JuanLesPins

  • Luebeck

  • Madrid

  • Malmoe

  • Marburg

  • Montpellier

  • PaloAlto

  • Pittsburgh

  • Rochester

  • Singapore

  • Szeged

  • Warsaw

You can see these themes in the gallery at http://latex-beamer.net. We specified the title, subtitle, author, and date of the seminar, which is then printed by \titlepage. We used a frame environment, which we have to use for each slide.

The next frame contains the table of contents. We provided the frame title Outline as an argument to the frame in curly braces. For the \tableofcontents command, we added the pausesections option. As a result of doing this, section titles are printed one-by-one with a pause in between. This gives us the opportunity to explain what the audience will hear before they read further.

Here, we used the \section and \subsection commands just like in a normal LaTeX document. The heading is not directly printed. The sections and subsections are printed in the frame margin with the current position highlighted.

To get a bulleted list, we used an itemize environment just as we would in a normal LaTeX document. The environments enumerate for numbered lists and description for descriptive lists also work in the beamer frames.

To highlight information, we used the so-called block environments. Besides the standard block environment, we can use the exampleblock and alertblock commands to get a different style or color. The chosen theme determines the appearance of those blocks.

The \alert command is used to emphasize more distinctly, as seen in the last frame.

Now, you have the template and tools to create your presentation.

Tip

Consider the following while designing a presentation:

  • Keep time constraints in mind; a frame per minute is a good rule of thumb.

  • Use few sections, logically split in subsections; it is better to avoid subsubsections.

  • Use self-explanatory titles for sectioning and frames.

  • Bulleted lists help to keep things simple.

  • Consider avoiding numbering references; one rarely cares about a reference to theorem 2.6 during a talk.

  • Don't disrupt the reading flow with footnotes.

  • Graphics, such as diagrams, help the audience with visualization.

  • Slides should support your talk, not the other way round. Did you already bear with a presentation where the speaker just read aloud the text from the slides and used fancy transition effects? You can do it better.

There's more...

The beamer package has unique capabilities and an extraordinary design. We will explore it in the following pages.

Using short titles and names

Besides the title page, the title of the presentation and the author's name are additionally printed at the bottom of each frame. The exact position depends upon the chosen theme.

However, for long titles or names, the space might be insufficient. You can provide short versions to be used in such places, for example, by specifying the following commands:

\title[Short title]{Long Informative Title}
\author[Shortened name]{Author's Complete Name}
\date[2015/06/24]{Conference on X at Y, June 24, 2015}

The same is possible for the \institute and \subtitle commands, if you would use these commands in your presentation.

You can provide short names for sections and subsections in exactly the same way, so they would better fit into their field within the frame margin; just use the optional argument in square brackets. The \part and \subsubsection commands work similarly, they can get a short name in square brackets as well.

Uncovering information piecewise

Showing a complete slide at once may be a bit distracting. People may read ahead instead of listening to you. You can take them by the hand by displaying the content step by step.

The simplest way is to insert a \pause command. It can go between anything such as text, graphics, and blocks. It also works between two \item commands in a bulleted list; however, consider pausing between whole lists instead of items. Simply use it like we will do in the following line of code:

Text\pause more text\pause\includegraphics{filename}

Such a frame is then layered; that is, divided into overlays. They are internally numbered. If you would like to show something at a certain overlay, you can tell the beamer package when to uncover it:

\uncover<3->{Surprise!}

This shows your text on slide 3 of the current frame; and it will stay on the following slides in that frame. Omit the dash for restricting it to only slide 3. You can also list multiple slides, such as <3,5>, give ranges such as <3-5>, and mix the two, as in <3,5->.

This syntax works with overlay-specification-aware commands. Among them, there are \item, \includegraphics, and even \renewcommand, so you can use them with an overlay specification such as the following:

\includegraphics<3->{filename}

Overlays should not be too fancy. A presentation needs a linear structure; complicated overlays may be handy for showing and hiding annotation to an object, while you explain that.

Refer to the beamer manual for more information on using overlays. You can open that manual via texdoc beamer in Command Prompt, or online at http://texdoc.net/pkg/beamer.

Splitting frames in columns

You can arrange text and images in multiple columns on a frame. This is especially handy for images with explanatory text. Let's take a look at a sample:

\begin{frame}
  Some text which can use whole frame width
  \begin{columns}[t]
    \begin{column}{0.45\textwidth}
      Sample text in\\
      two lines
    \end{column}
    \begin{column}[T]{0.45\textwidth}
      \includegraphics[width=3cm]{filename}
    \end{column}
  \end{columns}
\end{frame}

We started the multicolumn area using the column environment. You can specify alignment options t, b, or c for top, bottom, or centered alignment of the column. Centered is the default. While t aligns at the baseline of the first line, which is common in LaTeX, there's a handy additional option, T, which aligns at the very top.

Each column is created by the column environment. The column width is given as an argument. It understands the same positioning options, so you can override what you set in the surrounding columns environment. We added the [T] option here, because an image has its baseline at its bottom, and we want to change it to the very top.

Showing an outline for each section

You can tell the beamer package to give an outline at the beginning of each section by specifying the following code:

\AtBeginSection{
  \begin{frame}{Outline}
    \tableofcontents[currentsection]
  \end{frame}}

You can also use the \AtBeginSection command to insert different lines of code. If something should happen in case of a starred \section* too, you can insert the corresponding code within an optional argument in square brackets after \AtBeginSection.

Removing the navigation symbols

By default, every slide shows small navigation symbols; here, at the bottom of a frame. If you don't need them, you can save that space and reduce the distraction by specifying the following line of code:

\setbeamertemplate{navigation symbols}{}

Changing the font

The default font set with the beamer package is Computer Modern. You can change it to other fonts as discussed in Chapter 3, Adjusting Fonts.

The default font is sans serif. Even the math formulas are sans serif. With a low projector resolution, or at some distance, this can be more readable than with a serif font.

However, if you would like to change to a serif font, you can load the corresponding font theme in the preamble:

\usefonttheme{serif}

Another available font theme is professionalfonts, which actually doesn't change fonts, but simply uses the set you specify separately. Furthermore, there are structurebold, structureitalicserif, and structuresmallcapsserif, which change the font in the structure, that is, in headlines, footlines, and sidebars, to such a shape combination.

Changing the color

The quickest way to change colors is by loading a theme with a thoughtful selection of colors for the various structure elements. Use a single command as follows:

\usecolortheme{dolphin}

There are outer color themes, providing a color set for headlines, footlines, and sidebars. The author of the beamer package gave them sea animal names: dolphin, whale, and seahorse. Then, there are inner color themes for elements, such as color blocks, with names of flowers: lily, orchid, and rose. Combine inner and outer color themes as you like.

Finally, there are complete themes covering all structure aspects: albatross, beaver, beetle, crane, dove, fly, monarca, seagull, spruce, and wolverine. They are named after flying animals, except wolverine, beaver and spruce, which are external additions.

A lot of names, you may go through them using the \usecolortheme command to find the color set you like the most.

Loading a theme from the Internet

With some labor, you can create your very own theme. The extensive beamer manual will guide you. However, you may save a lot of time; beamer is very popular among academic users, who already use LaTeX for their papers, so you can find a lot of themes prepared for universities and institutes, but also designed by various beamer users.

You can find an overview of beamer themes at http://latex-beamer.net.

Explore the gallery there, download the theme you like, add your logo, and tweak it. Instructions for using the themes that are available on the website.

Providing a handout

You can give your audience a printed version of the slides. Just create a version of your document with the handout option, so no overlays will be used:

\documentclass[handout]{beamer}

Slides are commonly small, so it's good to print several slides on a single page:

\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[a4paper,
  border shrink=5mm,landscape]

This prints four slides on an A4 page in landscape. You can get bigger prints, two slides on each page, in portrait mode, by specifying the following line of code:

\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]

We used the pgfpages option, a utility package that comes with the pgf package.

See also

For the best quality with included graphics, refer to Chapter 4, Working with Images. In Chapter 9, Creating Graphics, you can find recipes for quickly creating diagrams and charts, which are good tools for visualizing data in a presentation.