4

I am doing a presentation with Beamer and I need help with the use of \only<.> and \boxed{}.

I would like to get the following effect:

  1. a=b+c

  2. a=b+c

    c=d

  3. a=b+d

    c=d

  4. a=b+\boxed{d}

    c=d

I used the following code but I don't like the effect because when it put the box around d it moves also "c=d". Could someone help me to find a different code?

\begin{align*}
a=b+\only<1-2>c
\only<3>{d}
\only<4>{\boxed{d}}
\end{align*}
\pause
c=d

So I would like to get the "d boxed" after that "a=b+d" appears without moving "c=d".

Could someone help me?

2 Answers 2

1

First: you don't use align properly. You have to write "c=d" inside the environementalign, and "glue" the two equations with an &.

Second: you have to precisely align "d" correspondig to the differences between the width of d and \boxed{d}.

There are two solutions (assuming that the frame is center-aligned); both of the should work, but shomehow the second is better.

\documentclass{beamer}

% For both solutions
\usepackage{calc}

% Just for the second solution
\newlength{\firslength}
\settowidth{\firslength}{\boxed{d}}
\newlength{\secondlength}
\settowidth{\secondlength}{d}

\begin{document}

\begin{frame}

% First solution
\begin{align*}
a=&b+\only<1-2>{\hspace*{(\widthof{\boxed{d}}-\widthof{d})/2}c\hspace*{(\widthof{\boxed{d}}-\widthof{d})/2}}%
\only<3>{\hspace*{(\widthof{\boxed{d}}-\widthof{d})/2}d\hspace*{(\widthof{\boxed{d}}-\widthof{d})/2}}%
\only<4>{\boxed{d}}\\%
\uncover<2->{c=&d}%
\end{align*}

% Second solution
\begin{align*}
a=&b+\only<1-2>{\hspace*{\dimexpr(\firslength-\secondlength)/2}c\hspace{\dimexpr(\firslength-\secondlength)/2}}%
\only<3>{\hspace*{\dimexpr(\firslength-\secondlength)/2}d\hspace{\dimexpr(\firslength-\secondlength)/2}}%
\only<4>{\boxed{d}}\\%
\uncover<2->{c=&d}%
\end{align*}

\end{frame}

\end{document}

enter image description here

1

The problem here is that \boxed{d} has a different width than d. Tom Solid's solution, unfortunately, looks awkward with the extra spacing inserted.

I'm not sure where you're getting \boxed from (I guess it gets loaded indirectly by beamer) but I've found it defined in multiple packages as:

\newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}

(or its equivalent). Digging into the definitions of \fbox there is extra space of \fboxsep surrounding the box contents inside the box plus the width of the lines which is \fboxrule. We can use this to make a new command, \bxed (or whatever you prefer to call it) which will remove the space that has been added so that the box spills into the existing white space around d when its printed.

\newcommand{\bxed}[1]{\mbox{\kern-\fboxsep\kern-fboxrule\boxed{#1}\kern-\fboxsep\kern-fboxrule}}

This should give the desired result.

Also, the & in the align environment should come before the = and not after it. You'll notice in Tom's example that the spacing between a and = is larger than the spacing between = and b. Moving the ampersand fixes that issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .