# Avoiding jumps when using beamer overlays

I have the following piece of code in a beamer slide to put the curly brackets under the equation on the second slide:

\begin{equation*}
a = \alt<1>{b+c+d}{\underbrace{b+c+d}_{\text{some text}}}.
\end{equation*}

This causes jumps in the slides. I was wondering how I should avoid this?

I tried to wrap the equation inside an overprint environment (as suggested in Avoiding jumping frames in beamer) but it didn't help.

• Add a phantom of the underbrace to the first slide – MaxNoe Sep 28 '15 at 8:53
• Which part of underbrace should be put inside phantom? – Mani Bastani Parizi Sep 28 '15 at 8:56
• This code does not reproduce the problem even when the obvious document structure is added because the underbrace is never shown. Since only one slide is produced, no jump is possible. – cfr Sep 28 '15 at 22:14

This creates a new environment overlayauto which works like overlayarea but computes the height, width and depth from the data.

Note: this is like putting an \mbox in a math environment in that you need to use $...$ inside.

\documentclass{beamer}
\usepackage{environ}

% used to replace \only
\def\testonly<#1>#2{\setbox0=\hbox{#2}%
\ifdim\ht0>\maxheight\relax\maxheight=\ht0\fi
\ifdim\dp0>\maxdepth\relax\maxdepth=\dp0\fi
\ifdim\wd0>\maxwidth\relax\maxwidth=\wd0\fi
}
\NewEnviron{overlayauto}[1][\normalfont\raggedright]% #1 = minipage optons
{% get dimentsions from data
\dimendef\maxheight=0
\dimendef\maxwidth=1
\dimendef\maxdepth=2
\maxheight=0pt
\maxdepth=0pt
\maxwidth=0pt
\let\temp=\only
\let\only=\testonly
\BODY
\let\only=\temp
\raisebox{0pt}[\maxheight][\maxdepth]%
{\begin{minipage}[t]{\maxwidth}
#1\BODY
\end{minipage}}
}
\begin{document}
\begin{frame}
above
\begin{equation*}
a=\begin{overlayauto}
\only<1>{$b+c+d$}%
\only<2>{$\underbrace{b+c+d}_{\text{some text}}$}
\only<3>{$\overbrace{b+c+d}^{\text{some text}}$}
\end{overlayauto}
\end{equation*}
below
\end{frame}
\end{document}