[Tex/LaTex] Beamer overlay only/visible

beameroverlays

I am trying to change a formula between two slides. Here is an MWE

\documentclass{beamer}

\begin{document}

\begin{frame}{Title}
Something before\\
\bigskip
$%
B\left(%
\only<1>{A_2[i]}%
\only<2>{A_L[i]}%
\right) =%
\only<1>{C_1 + C_2}%
\visible<2>{\displaystyle\sum_{k=1}^{L} C_k}%
\quad \text{text here }%
\only<1>{a,b,c,}%
\only<2>{a,b,c,\ldots,z}
$

\end{frame}

\end{document}

As you can see, there is a problem with the position of "text here" in the first slide. If I put only instead of visible, that problem is solved but then everything moves during the transition. Is there a way to solve both issues?

Best Answer

The command \vphantom in useful in this case. It will reserve the vertical space required by the sum and thus prevent "wobbling" of the formula during overlays.

\documentclass{beamer}

\begin{document}

\begin{frame}{Title}
Something before\\
\bigskip
$%
B\left(%
\only<1>{A_2[i]}%
\only<2>{A_L[i]}%
\right) =%
\only<1>{C_1 + C_2 \vphantom{\displaystyle\sum_{k=1}^{L} C_k}}%
\only<2>{\displaystyle\sum_{k=1}^{L} C_k}%
\quad \text{text here }%
\only<1>{a,b,c,}%
\only<2>{a,b,c,\ldots,z}
$

\end{frame}

\end{document}