5

I work hard these days on writing animated graphical beamer presentation, which sometimes contain over 100 slides. I find that I need to think across three interacting dimensions:

  1. The time dimension, in which I have to think about the order of the slides.
  2. The planar dimension, in which I have to think about the placement of graphical objects on the slide.
  3. The code flow dimension, in which the LaTeX commands are executed in the order they occur in the code. LaTeX allows you to refer to commands which are defined later in the code, since it is ok for a command \a' to refer to a command\b' even if \b is defined below it, as long as \b is defined somewhere below. In contrast, with tikz you cannot refer to a named node, unless it was defined earlier. This complicates the design, since sometimes you need to place a node in a position which is relative to another node, even though that other node does shows much later in the presentation.

I wonder if people here have tips for workflow and design to help in this process. Some tips I gathered in this site include

Here are several things which I still do not know how to manage:

  • Range specification in overlays which uses relative offsets, that is something in a syntax such as \uncover<(-6>-(+17)>{snark} which should present "snark" on the range of slides starting from 6 before the current and ending with the slide occurring 17 slides after it.

  • Making saved slide labels obey scope rules, so that \savepause{label} could be used in a macro which can be invoked several times.

  • Forcing beamer to recalculate the layout of a slide, based on the current values of some macros.

  • Taking snapshots of an animation made with overlays, so that the essence of an animation can be saved into handouts.

  • What restrictions, if any, are there on placing macro names in ranges beamer's overlay specification? Can you freely define macros to a slide number and then use it within the angular brackets.

But, more importantly, I am seeking tools and answers to questions I have not been able to formulate: effective tips and

5

Here is a, somewhat loose, collection of tips and tricks I frequently use to manage beamer frames with lots of slides and complicated animations.

Code Flow Dimension with TikZ

I do not use beamer's overlay commands (\visible<>, \only<>, and so on). Instead I always draw all elements, but hide them on the slides they should not appear. To specify the visibility, I use a visible on=<...> TikZ style as follows (taken from Mindmap tikzpicture in beamer (reveal step by step), look there for a complete MWE):

  % Keys to support piece-wise uncovering of elements in TikZ pictures:
  % \node[visible on=<2->](foo){Foo}
  % \node[visible on=<{2,4}>](bar){Bar}   % put braces around comma expressions
  %
  % Internally works by setting opacity=0 when invisible, which has the 
  % adavantage (compared to \node<2->(foo){Foo} that the node is always there, hence
  % always consumes space that (foo) is always available.
  %
  % The actual command that implements the invisibility can be overriden
  % by altering the style invisible. For instance \tikzsset{invisible/.style={opacity=0.2}}
  % would dim the "invisible" parts. Alternatively, the color might be set to white, if the
  % output driver does not support transparencies (e.g., PS) 
  %
  \tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }

With this approach, all named elements (especially nodes) are always there, so you can use them for coordinate calculations even on slides they are not visible. Moreover, the tikzpicture always has the complete size, preventing the frequently asked issue of "jumping images".

The same argument applies to highlighting effects (e.g., turn node red on slide 2). For those, I use the following style (originally taken from Matthew Leingang's answer to How to make beamer overlays with Tikz node):

% Key to apply style on specific overlays only
% usage (e.g.): \node[onslide=<2->{fill=red}]{I am red on slide 2!};
%
% see also: https://tex.stackexchange.com/questions/6135/how-to-make-beamer-overlays-with-tikz-node 
%
\tikzset{onslide/.code args={<#1>#2}{%
  \only<#1>{\pgfkeysalso{#2}} 
}}

Of course, you could easily combine all this with other styles or TikZ scopes. IMHO, all this makes the code much better readable than the standard overlay commands. I have been using this approach for a couple of years.

Numbering of overlay steps

If developing lager animations, it is generally a good idea to use relative overlay specification where ever possible (and thanks to Joseph's answer to Relative overlay specification in beamer? I have learned that this mechanism is really powerful).

Nevertheless, at times you will find yourself in the situation that you have to use absolute numbers or you just want to use them, because they make the code better readable:

\begin{frame}{Uncovering piecewise}
  \begin{tikzpicture}[every node/.style={fill=red!30, draw=red}]
    \node{Foo}
      child[visible on=<3->]{node {Bar}}
      child[visible on=<2->]{node {Baz}}
    ;  
  \end{tikzpicture}
  \par
  \only<3>{COOL PICTURE!}
\end{frame}

With absolute numbers, however, it can become a real a PITA if you later want to insert an intermediate step and, hence, have to increment all subsequent numbers manually.

To prevent situations like that, I have adopted the line numbering scheme from my early days of BASIC programming: Initially use only multiples of 10, so that there is some space to later add lines "in between". To prevent beamer creating 10 slides for each animation step, I then manually restrict the steps to use on the frame level:

\begin{frame}<1,20,30>{Uncovering piecewise}
  \begin{tikzpicture}[every node/.style={fill=red!30, draw=red}]
    \node{Foo}
      child[visible on=<30->]{node {Bar}}
      child[visible on=<20->]{node {Baz}}
    ;  
  \end{tikzpicture}
  \par
  \only<30>{COOL PICTURE!}
\end{frame}

Tailoring Animations for Handouts

The idea to tailor animation steps also on the frame level can also be applied for the easy problem-specific tailoring of your animations, such as for the handout.

In handout mode, beamer usually collapses all slides of a frame to a single slide and uses that for the handout. However, I often want to provide some steps of the animation (but not all of them) in the handout. In that case, one can use the mode specifiers (all:, handout:, beamer:) to tell beamer that an certain animation elements should also or only be part of the handout/presentation slides, respectively.

Instead of specifying this element-wise, which quickly becomes a nightmare to maintain, I use the all:-specifier for all overlay specifications, so that each step of the animation would also become part of the handout. I then select the slides I actually want in the handout on the frame level:

% Skip slide 2 in handout
\begin{frame}<beamer|handout:1,3>{Uncovering piecewise}
  \begin{tikzpicture}[every node/.style={fill=red!30, draw=red}]
    \node{Foo}
      child[visible on=<all:3->]{node {Baz}}
      child[visible on=<all:2->]{node {Bar}}
    ;  
  \end{tikzpicture}
  \par
  \only<all:3>{COOL PICTURE!}
\end{frame}

In my process, creating the handout (and deciding which slides should be in it) is typically one of the last actions I take. By this approach, it becomes very easy to tailor the handout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.