# Beamer: Mixing absolute overlays with relative overlays

I have the following code snippet that creates the overlays in the desired order. However, setting the beamerpauses-counter myself is quite ugly. How can I avoid setting the counter myself and get the same output? The problem seems to come from mixing \only with relative overlay numbers, but I'm not sure how to avoid this.

\documentclass{beamer}
\begin{document}
\begin{frame}{Slide}
\begin{itemize}
\item Blabla
\item Blabla
\item<3-> Blabla
\end{itemize}
\only<1-2>{
A\only<2>{B}
}
\only<3->{ \setcounter{beamerpauses}{3}
\only<+>{First:}
\only<.>{$1+1=$}
\only<+>{$2$}
\only<+>{Second:}
}
\end{frame}
\end{document}

## 1 Answer

Tricky one, but doable if you work systematically. You might want to look at my guide to beamer overlays (also available as a TUGboat article, currently only to TUG members).

What you need to do is use the idea of relative slide positions, indicated by +, . and numbers in parenthesis. I'll explain the detail in comments in the code (trying to gie this up-front is tricky):

\documentclass{beamer}
\begin{document}
\begin{frame}{Slide}
\begin{itemize}
% First item on slide 1 onwards. The + will be replaced here by a 1 here:
% of course if you add material before hand absolute value will change!
\item<+-> Blabla
% Second item on same slide as first: . repeats the previous number
\item<.-> Blabla
% Third item appears on third slide: + is slide 2 here, so +(1) is slide 3.
\item<+(1)-> Blabla
\end{itemize}
% Repeat the preceding + (2) but back-up one to 1, with the second .
% replaced simply by 2.
\only<.(-1)-.>{A}%
% Again, repeat 2 (the last value + stood for)
\only<.>{B}%
% Auto-increment + to 3 and insert
\only<+>{First:}%
% Repeat 3 again
\only<.>{$1+1=$}%
% Two simple auto-increments
\only<+>{$2$}%
\only<+>{Second:}%
\end{frame}
\end{document}

Done this way, nothing is hard-coded so it should be possible to use the code flexibly.

(To do this sort of thing, I'd start with the hard-coded numbers then replace one at a time by the relative specs.)

• It seems the main task is to unroll the nested \only usages, thanks! The link does not seem to work. – Heinrich Ody Jul 19 '14 at 13:48
• @HeinrichOdy Yes, nested conditionals are risky (the + gets incremented each time you use it, so \only<+>{\only<+> ... turns into something like \only<3>{\only<4> .... – Joseph Wright Jul 19 '14 at 13:51