# Uncover a multiline equation with beamer

I am using the beamer class for a presentation and amsmath package for the math mode. If I uncover the formula in the following way, the formula jumps between slides, which is not intended.

\begin{frame}
\only<1>{
\begin{multline*}
S(1,\dots,s) = \underbrace{\sum_{m=1}^{m_t} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{entropy estimate with correlation order}\, m_t} \\
+ \underbrace{\sum_{m=m_t+1}^{s} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{correlations of order higher than}\, m_t}
\end{multline*}}
\only<2->{
\begin{multline*}
S(1,\dots,s) = \underbrace{\sum_{m=1}^{m_t} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{entropy estimate with correlation order}\, m_t} \\
\xcancel{+ \underbrace{\sum_{m=m_t+1}^{s} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{correlations of order higher than}\, m_t} }
\end{multline*}}
\end{frame}


if I uncover its specific part directly, the alignment fails for the first slide and is only correct in the second slide (I tried also with \shoveright :( ):

\begin{frame}
\begin{multline*}
S(1,\dots,s) = \underbrace{\sum_{m=1}^{m_t} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{entropy estimate with correlation order}\, m_t} \\
\uncover<1>{+ \underbrace{\sum_{m=m_t+1}^{s} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{correlations of order higher than}\, m_t}}
\uncover<2->{\xcancel{+ \underbrace{\sum_{m=m_t+1}^{s} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{correlations of order higher than}\, m_t}}}
\end{multline*}
\end{frame}


So my question is: How do I uncover multiline equations within beamer?

• Bort, please always give a full and compilable example. It is normally just a few lines longer, but avoids guesses which packages you used. I had to look up the cancel package by myself. Feb 20, 2011 at 17:11

You shouldn't use \onlys for exclusive material, but the overprint environment together with \onslide. It ensures that the required size is reserved on any of the slides and therefore avoids most issues with jumping text:

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{cancel}
\begin{document}

\begin{frame}%
\begin{overprint}
\onslide<1>
\begin{multline*}
S(1,\dots,s) = \underbrace{\sum_{m=1}^{m_t} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{entropy estimate with correlation order}\, m_t} \\
+ \underbrace{\sum_{m=m_t+1}^{s} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{correlations of order higher than}\, m_t}
\end{multline*}
\onslide<2>
\begin{multline*}
S(1,\dots,s) = \underbrace{\sum_{m=1}^{m_t} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{entropy estimate with correlation order}\, m_t} \\
\xcancel{+ \underbrace{\sum_{m=m_t+1}^{s} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{correlations of order higher than}\, m_t} }
\end{multline*}
\end{overprint}
\end{frame}%

\end{document}


This should answer your question about how to uncover multiline equations within beamer. However, the \xcancel macro still causes the second line to jump up, which is a different problem.

• thank you very much... this solves the problem. Instead of canceling I change the textcolor to light gray and problem is solved. Oh, yes sorry for the packages. I copied this from a longer document and forgot about the header.
– user3722
Feb 20, 2011 at 17:29

I must admit that I hate typing out stuff more than once, so I don't like either solution so far presented! So here's a variation on Hendrik's solution that works by making the \xxcancel command overlay-aware.

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{cancel}
\newcommand<>{\xxcancel}[1]{\alt#2{\xcancel{#1}\vphantom{#1}}{#1}}
\begin{document}

\begin{frame}
\begin{multline*}
S(1,\dots,s) = \underbrace{\sum_{m=1}^{m_t} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{entropy estimate with correlation order}\, m_t} \\
\xxcancel<2->{{} + \underbrace{\sum_{m=m_t+1}^{s} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{correlations of order higher than}\, m_t} }
\end{multline*}
\end{frame}

\end{document}

• +1, great! So \alt does the trick here; you may want to emphasize that in your answer (that should be the accepted one!). Why does \alt work better than \only? Feb 21, 2011 at 9:42
• @Hendrik: Well, \alt is what you want in this case since you want the cancellation replaced by the under text. Also, it's acting in two different ways: the \onlys in the question are outside the mathematics but the \alt is inside. I guess it's pure luck (or good design) that the \xcancel doesn't seem to add any extra space so the equation doesn't jump about on the page, otherwise something more complicated would be needed (not knowing of the cancel package, I use TikZ to draw big lines across the page for this sort of thing). Feb 21, 2011 at 10:05
• @Andrew: No, the \xcancel does give different vertical spacing; otherwise the \vphantom wouldn't be needed. So it's really that \alt is better here. Wasn't obvious to me that it's inside the math; maybe that's why it's better. Feb 21, 2011 at 10:24
• @Hendrik: Actually, my original statement is correct: \xcancel doesn't add any extra space! It's a little odd that it removes some, which is what your \vphantom corrects for. This is actually quite a complicated question as there are several distinct issues: uncovering mathematics, ensuring that nothing jumps, and making a command overlay-aware. Feb 21, 2011 at 10:33
• @Andrew: Yes, I also found that odd. But I insist that \xcancel does add (negative) vertical space! ;-) Feb 21, 2011 at 10:44

Martin essentially gave you what you need. Here's how you can prevent the second line from jumping up:

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{cancel}
\newcommand\xxcancel[1]{\xcancel{#1}\vphantom{#1}}
\begin{document}

\begin{frame}
\begin{overprint}
\onslide<1>
\begin{multline*}
S(1,\dots,s) = \underbrace{\sum_{m=1}^{m_t} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{entropy estimate with correlation order}\, m_t} \\
+ \underbrace{\sum_{m=m_t+1}^{s} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{correlations of order higher than}\, m_t}
\end{multline*}
\onslide<2>
\begin{multline*}
S(1,\dots,s) = \underbrace{\sum_{m=1}^{m_t} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{entropy estimate with correlation order}\, m_t} \\
\xxcancel{{} + \underbrace{\sum_{m=m_t+1}^{s} (-1)^{m+1} \sum_{i_1<\dots<i_m} I(i_1,\dots,i_m)}_{\text{correlations of order higher than}\, m_t} }
\end{multline*}
\end{overprint}
\end{frame}

\end{document}


Making the second line not jump revealed that the + in the second line moved; to prevent this, I added {} in front of it.