4. \onslide command

There are some commands of Beamer for which the overlay specification has a especial effect. These commands are, essentially, sophisticated versions of \pause, and will give us the ability to fine tune our overlays. The first command we are going to see is probably the most complex, which is

\onslide <modifier> <overlay spec> {text}

First of all, this command has the strange property that the {text} parameter is optional, although it is given in braces. Depending on whether or not this parameter is present, the behavior of the command changes. Also, the command has a <modifier> that precedes the overlay specifications, and if present it can
be either a + or a *.

• If no {text} is given, everything that follows this command will only be shown on the specified slides (if you put no specification, it will be shown on all slides). On the slides out of the specification, the text still occupies space. As with the \pause command, the effect transcends block groups.
• If the <modifier> + is given, hidden text will not be treated as covered but as invisible. If the <modifier>* is given, which can be done only when {text} is present, for the slides in which is invisible the text is thrown away.

Here is an illustrative example:

% Overlay specifications \onslide command
\documentclass{beamer}

% Theme choice:
\usetheme{Frankfurt}

\begin{document}

\begin{frame}{Onslide command}
This is shown on all slides.

\onslide <1-3>
\begin{itemize}
\item This list will only be shown
\item on slides 1, 2 and 3.
\end{itemize}

\onslide<1,4>
I appear just on slides 1 and 4.

\end{frame}

\end{document}

which yields to 4 slides:

Don’t worry if this command was too much for you. The following ones are much simpler, and follow the same logic but more restricted.

5. \only command

In some sense, this command is an all in one which can be used as follows:

\only < overlay spec> {text } < overlay spec >

makes the {text} appear only on the specified slides, although only one overlay specification may be present. For the other slides, the text is simply thrown away, so it occupies no space. This command has the same effect as \onslide* <overlay spe> {text}.

The last overlay specification is put so that you can define new commands that are overlay specification-aware. The following example change text color only on slide 2:

% Overlay specifications \only command
\documentclass{beamer}

% Theme choice:
\usetheme{Frankfurt}

\begin{document}

\begin{frame}{Only command}
\only<2>{\color{red}}  This text is red only on slide 2.
\end{frame}

\end{document}

Compiling this code yields:

6. \uncover command

The command:

\uncover < overlay spec> {text }

uncovers the text only on the specified slides. On the other slides the text still occupies space, and in fact it is typeset, but it is not shown (you can have it shown as transparent, so that the interested audience in the presentation can get a feeling for what will come next, but we won’t go into details here;
maybe in another tutorial). Check the following illustrative example:

% Overlay specifications \uncover command
\documentclass{beamer}

% Theme choice:
\usetheme{Frankfurt}

\begin{document}

\begin{frame}{Uncover command}
If you want to learn Beamer\uncover<2>{, follow latex-beamer.com!}
\end{frame}

\end{document}

which yields to the following two slides:

7. \invisible command

The command:

\invisible < overlay spec> {text }

makes text completely invisible in the specified slides, although in every slide the text occupies space. Consider the same previous example:

% Overlay specifications \invisible command
\documentclass{beamer}

% Theme choice:
\usetheme{Frankfurt}

\begin{document}

\begin{frame}{Invisible command}
If you want to learn Beamer\invisible<2>{, follow latex-beamer.com!}
\end{frame}

\end{document}

Compiling this code yields:

8. \alt command

Let’s dive now into commands that offer different functionality than the previous command. First, we have

\alt < overlay spec> {default text }{alternative text} < overlay spec >

which shows the default text on the specified slides, while in the others is shown the alternative text. The specification must always be present, but only one of them. For example:

% Overlay specifications \alt command
\documentclass{beamer}

% Theme choice:
\usetheme{Frankfurt}

\begin{document}

\begin{frame}{Alternative command}
\alt<2>{We are on slide 2!}{We are not on slide 2}
\end{frame}

\end{document}

Compiling this code yields:

9. \temporal command

The following command:

\temporal < overlay spec> {before slide text } {default text }{after slide text}

which alternates between the three given texts, depending on the relative position of the current slide with respect to the specified slides: if the current slide is temporally before the specified, the before slide text is shown; if it is inside the specified, the default text is shown; and if it is after the specified, the after slide text text is shown. If the overlay specification is not a single interval but has a hole in it, the hole is considered part of the default text.

Continue or check the Next Lesson: 11 Insert a GIF into LaTeX Beamer — Short guide