summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/beamer/doc/beamerug-tricks.tex
blob: add83ca2b6d1345ade42c9716cb428776f3c1836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
% !TeX root = beameruserguide.tex
% Copyright 2003--2007 by Till Tantau
% Copyright 2010 by Vedran Mileti\'c
% Copyright 2015 by Vedran Mileti\'c, Joseph Wright
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
% See the file doc/licenses/LICENSE for more details.

\section{How To Uncover Things Piecewise}


\subsection{Uncovering an Enumeration Piecewise}

A common usage of overlays is to show a list of points in an enumeration in a piecewise fashion. The easiest and most flexible way to do this is the following:
\begin{verbatim}
\begin{itemize}
\item<1-> First point.
\item<2-> Second point.
\item<3-> Third point.
\end{itemize}
\end{verbatim}

The advantage of this approach is that you retain total control over the order in which items are shown. By changing, for example, the last specification to |<2->|, you can have the last two points uncovered at the same time.

A disadvantage of the approach is that you will have to renumber everything if you add a new item. This is usually not such a big problem, but it can be a nuisance.

To automatize the uncovering, you can use the following code:
\begin{verbatim}
\begin{itemize}[<+->]
\item First point.
\item Second point.
\item Third point.
\end{itemize}
\end{verbatim}

The effect of the |[<+->]| is to install a \emph{default overlay specification}, see the definition of |itemize| for details.

Now, suppose you wish the second and third point to be shown at the same time. You could achieve this by adding the specification |<2->| to either the second or third |\item| command. However, then you still have to do some renumbering if you add a new item at the beginning. A better approach is to temporarily use a different overlay specification and the dot-notation:
\begin{verbatim}
\begin{itemize}[<+->]
\item First point.
\item<.-> Second point.
\item Third point.
\end{itemize}
\end{verbatim}

You might wish to build your own macros based on these ideas (like an |itemstep| environment or a |\itemlikeprevious| command).


\subsection{Highlighting the Current Item in an Enumeration}

If you uncover an enumeration piecewise, it is sometimes a good idea to highlight the last uncovered point to draw the audience's attention to it. This is best achieved as follows:
\begin{verbatim}
\begin{itemize}
\item<1-| alert@1> First point.
\item<2-| alert@2> Second point.
\item<3-| alert@3> Third point.
\end{itemize}
\end{verbatim}

or
\begin{verbatim}
\begin{itemize}[<+-| alert@+>]
\item First point.
\item Second point.
\item Third point.
\end{itemize}
\end{verbatim}

Note that this will draw the little item symbol also in red.


\subsection{Changing Symbol Before an Enumeration}

When uncovering a list of tasks or problems, you may desire that the symbol in front of the last uncovered symbol is, say, a ballot~X, while for the previous items it is a check mark (you'll find these characters in some Dingbats fonts).

The best way to achieve this is to implement a new action environment. If this action is activated, it temporarily changes the item symbol template to the other symbol:
\begin{verbatim}
\newenvironment{ballotenv}
{\only{%
  \setbeamertemplate{itemize item}{code for showing a ballot}%
  \setbeamertemplate{itemize subitem}{code for showing a smaller ballot}%
  \setbeamertemplate{itemize subsubitem}{code for showing a smaller ballot}}}
{}

\setbeamertemplate{itemize item}{code for showing a check mark}
\setbeamertemplate{itemize subitem}{code for showing a smaller check mark}
\setbeamertemplate{itemize subsubitem}{code for showing a smaller check mark}
\end{verbatim}

The effect of the code is to install a check mark as the default template. If the action |ballot| is now requested for some item, this template will temporarily be replaced by the ballot templates.

Note that the |ballotenv| is invoked with the overlay specification given for the action directly following it. This causes the |\only| to be invoked exactly for the specified overlays.

Here are example usages:
\begin{verbatim}
\begin{itemize}
\item<1-| ballot@1> First point.
\item<2-| ballot@2> Second point.
\item<3-| ballot@3> Third point.
\end{itemize}
\end{verbatim}

and
\begin{verbatim}
\begin{itemize}[<+-| ballot@+>]
\item First point.
\item Second point.
\item Third point.
\end{itemize}
\end{verbatim}

In the following example, more and more items become ``checked'' from slide to slide:
\begin{verbatim}
\begin{itemize}[<ballot@+-| visible@1-,+(1)>]
\item First point.
\item Second point.
\item Third point.
\end{itemize}
\end{verbatim}

The important point is |ballot@+|. The funny |visible@1-,+(1)| has the following effect: Although it has no effect with respect to what is shown (after all, it applies to all slides), it ensures that in the enumeration the slide number 4 is mentioned. Thus there will also be a slide in which all three points are checked.


\subsection{Uncovering Tagged Formulas Piecewise}

Suppose you have a three-line formula as the following:
\begin{verbatim}
\begin{align}
  A &= B \\
    &= C \\
    &= D
\end{align}
\end{verbatim}

Uncovering this formula line-by-line is a little tricky. A first idea is to use the |\pause| or |\onslide| commands. Unfortunately, these do not work since |align| internally reprocesses its input several times, which messes up the delicate internals of the commands. The next idea is the following, which works a little better:
\begin{verbatim}
\begin{align}
  A &= B \\
    \uncover<2->{&= C \\}
    \uncover<3->{&= D}
\end{align}
\end{verbatim}

Unfortunately, this does not work in the presence of tags (so it works for the |align*| environment). What happens is that the tag of the last line is shown on all slides. The problem here is that the tag is created when |\\| is encountered or when |\end{align}| is encountered. In the last line these are already ``behind'' the |\uncover|.

To solve this problem, you can add an empty line without a tag and then insert a negative vertical skip to undo the last line:
\begin{verbatim}
\begin{align}
  A &= B \\
    \uncover<2->{&= C \\}
    \uncover<3->{&= D \\}
    \notag
  \end{align}
\vskip-1.5em
\end{verbatim}


\subsection{Uncovering a Table Rowwise}

When you wish to uncover a table line-by-line, you will run into all sorts of problems if there are vertical and horizontal lines in the table. The reason is that the first vertical line at the left end is drawn before the line is even read (and thus, in particular, before any |\onslide| command can be read). However, placing a |\pause| or |\uncover| at the end of the line before is also not helpful since it will then suppress the horizontal line below the last uncovered line.

A possible way to solve this problem is not to use either horizontal or vertical lines. Instead, coloring the lines using the |colortbl| package is a good alternative to structure the table. Here is an optically pleasing example, where the table is uncovered line-wise:
\begin{verbatim}
\rowcolors[]{1}{blue!20}{blue!10}
\begin{tabular}{l!{\vrule}cccc}
  Class & A & B & C & D \\\hline
  X     & 1 & 2 & 3 & 4 \pause\\
  Y     & 3 & 4 & 5 & 6 \pause\\
  Z     & 5 & 6 & 7 & 8
\end{tabular}
\end{verbatim}

By using |\onslide| instead of |\pause|, you can get more fine-grained control over which line is shown on which slide.


\subsection{Uncovering a Table Columnwise}

The same problems as for uncovering a table linewise arise for uncovering it columnwise.

Once more, using the |colortbl| package offers a solution. In the following example, the |tabular| header is used to insert |\onslide| commands, one for each column, that cover the entries in the column from a certain slide on. At the end of the last column, the |\onslide| without a specification ensures that the first column on the next row is once more shown normally.

Inserting a horizontal line is tricky since it will protrude over the full width of the table also in the covered version. The best idea is just not to use horizontal bars.
\begin{verbatim}
\rowcolors[]{1}{blue!20}{blue!10}
\begin{tabular}{l!{\vrule}c<{\onslide<2->}c<{\onslide<3->}c<{\onslide<4->}c<{\onslide}c}
  Class & A & B & C & D \\
  X     & 1 & 2 & 3 & 4 \\
  Y     & 3 & 4 & 5 & 6 \\
  Z     & 5 & 6 & 7 & 8
\end{tabular}
\end{verbatim}