# Beamer overlayarea within align environment

In my beamer presentation there are three equations in an align environment. First, they should be rendered as specified. In step 2, part of the first equation should have a box around it. In step 3, part of the second equation should have a box around it.

The problem is that the boxes increase the spacing and make content below jump.

Here is a MWE:

\documentclass{beamer}

\begin{document}

\begin{frame}

\begin{align}
\only<1,3>{\sum a &= b \\ }
\only<2>{\boxed{\sum a} &= b \\ }
\only<1-2>{\sum c &= d\\}
\only<3>{\boxed{\sum c} &= d \\ }
e &= f
\end{align}

\end{frame}

\end{document}


I tried overlayarea and overprint, but these gave me errors due to the align environment (Missing \$). Do you have any ideas?

Here, I create a complementary macro \nulboxed[color]{content} that takes the content and places it in a default white box. Thus, it takes the same space as \boxed, since it uses the same macro.

If one is unhappy with the asymmetric left/right space, one could always add \nulboxed wrappers around the b, d, and f terms, as well.

\documentclass{beamer}
\usepackage{xcolor}
\newcommand\nulboxed[2][white]{\textcolor{#1}{\boxed{\color{black}#2}}}
\begin{document}

\begin{frame}

\begin{align}
\only<1,3>{\nulboxed{\sum a} &= b \\ }
\only<2>{\boxed{\sum a} &= b \\ }
\only<1-2>{\nulboxed{\sum c} &= d\\}
\only<3>{\boxed{\sum c} &= d \\ }
\nulboxed{e} &= f
\end{align}

\end{frame}

\end{document}


Here is how it looks if one \nulboxed the right-hand terms, as I mentioned above:

The OP comments that the vertical space taken is too large. One can likely address that by \smashing the \boxed down to the size of its argument, by adding the following code to the preamble (it works for this MWE)

\let\svboxed\boxed
\def\boxed#1{\vphantom{#1}\smash{\svboxed{#1}}}

• This looks really great, except for one issue: I do not care much about asymmetric left-right space around the equals sign. But all terms on the left-hand side should be aligned right. If I add \nulboxed to every LHS, then the additional vertical space will be too much for the frame (because there are some more equations like "e = f").
– user61658
Aug 19 '15 at 8:06
• @jpmath I am not sure what you mean by right aligned, since that is already done (if you\nulbox{e} as I show in my MWE). See my FOLLOW UP to address the issue of vertical space. Aug 19 '15 at 10:25
• Thank you for your reply. You are right, the right alignment is done by adding the box on every LHS. It is that particular case, where the problem with vertical spacing occurs. Regarding your follow up, I can confirm that it fixes the spacing problem. Unfortunately, the black box from equation one has small parts where it is covered by the white box from equation two.
– user61658
Aug 19 '15 at 11:47
• @jpmath That would be the potential issue with \smash which is why I used the word "likely". There might be some case-by-case workarounds, but in general, I think avoiding the \smash would be preferable. Aug 19 '15 at 12:07
• I resolved the issue by using two separate commands, one for the equations which are boxed without the \smash, and one for the lines which are not boxed with the \smash.
– user61658
Aug 19 '15 at 12:43

here's an approach that uses \smash and some space adjustments to reposition the elements so that they appear to remain in the same locations when the slides are advanced.

\documentclass{beamer}

\newcommand{\fixit}{\mkern6mu{}}

\begin{document}

\begin{frame}

\jot=6pt
\begin{align}
\only<1,3>{\fixit \sum a \fixit &= b \\ }
\only<2>{\vphantom{\sum}\smash{\displaystyle\boxed{\sum a}} &= b \\ }
\only<1-2>{\fixit \sum c \fixit &= d\\}
\only<3>{\vphantom{\sum}\smash{\boxed{\sum c}} &= d \\ }
e \fixit &= f
\end{align}

\end{frame}

\end{document}


the \boxed elements are smashed, and the height of the \sum restored using \vphantom.

the lines are then too close together, so the space between them, defined by \jot (default = 3pt), is doubled.

to adjust the horizontal position, a small skip is inserted in place of the absent box verticals; the width of the skip was determined by experiment.