[Tex/LaTex] How to insert overlays in latex beamer


I have as many as 15-20 overlays within a frame. I am trying to highlight certain states in a state diagram. The problem is sometimes I would want to add an overlay, say between 5 and 6. I would need to increase the counter of all the overlays following 6 which can be quite annoying. I considered numbering overlays in multiples of 5 just so that I can insert an overlay later. However, each number would result in a new slide which is highly undesirable. Another solution is creating a separate frame. Is there a better way to handle this? Am I missing something obvious?

Best Answer

Here's an example of using incremental overlay specifications with offsets.

\begin{frame}[label=integral-of-x]{Example: Integral of $f(x) =x$}
Find $\int_0^3 x\,dx$.
\action<.->{For any $n$ we have $\alert<.(5)>{\Delta x = \frac{3}{n}}$ and for each $i$ between $0$ and $n$, $\alert<.(4)>{x_i = \frac{3i}{n}}$.}
\action<+->{For each $i$, take $x_i$ to represent $f$ on the $i$th interval.}
    \action<.->{\int_0^3 x\,dx = \lim_{n\to\infty} R_n }
        \action<+->{&= \lim_{n\to\infty} \sum_{i=1}^n \alert<.(1)>{f(x_i)}\,\alert<.(2)>{\Delta x}}
        \action<+->{ = \lim_{n\to\infty}\sum_{i=1}^n 
            \alert<+>{\left(\frac{\alert<.(1)>{3}}{\alert<.(1)>{n}}\right) }\\}
        \action<+->{&= \lim_{n\to\infty}\alert<.>{\frac{9}{n^2}} \alert<.(1)>{\sum_{i=1}^n i}}
        \action<+->{ = \alert<.(1)>{\lim_{n\to\infty}}\frac{9}{\alert<.(1)>{n^2}} 
            \cdot \alert<.>{\frac{\alert<.(1)>{n(n+1)}}{2}}}
        \action<+->{= \frac{9}{2}\alert<.>{\cdot 1}}

sample code output

Basically, <+-> means increment the pause count and apply this from that pause count onwards. <.-> means from the current pause count onwards (doesn't really do anything, but useful to be organized). And things like <.(5)> mean at the current pause count plus five. So you can insert things before or after without having to change pause counts explicitly. Of course, if you refer to overlays with <.> and <.(5)> and you want to insert something in between, you will need to change <.(5)> to <.(6)> or something similar.

My workflow in creating complex sequences like this is usually to map it out on paper. I will write down what should come on, go off, or change at each step. From there it's a matter of guess-and-check. The \includeonlyframes preamble command allows you to focus on one frame while developing.