I'm creating a presentation with the beamer
class. Assume I want to write this :
\begin{equation}
f(x)
\only<1>{= \cos(x)}
\only<2>{= 2\cos(x)}
\end{equation}
I have a problem because on the slide 2, the equation is longer and therefore
the equation is moving. If I replace only
by uncover
, there is a white
space on the slide 2.
I have the same problem for the align
environment
\begin{align}
f(x) &= \exp(x)\\
\only<2>{&= \cos(x)}
\only<3>{&= 2\cos(x)}
\end{align}
How can I replace part of an equation by something else without changing the placement of the other part of the equation ?
Edit
I will be more precise. I would like to find an efficient way to replace the
right hand side of an equality (for equation
or align
) without adding
extra white space and such that it keeps the equal sign at the same place.
For example :
\begin{equation}
\cos(x) =
\somecommand<1>{\dfrac{\exp{ix}+\exp{-ix}}{2}}
\somecommand<2>{\sum_{n=0}^{\infty}\dfrac{(-1)^{n}}{2n+1}x^{2n+1}}
...
\somecommand<n>{some other equality with a given lenght}
\end{equation}
- If
\somecommand
is\only
then the whole equality will move from slide 1 to 2. - If
\somecommand
is\uncover
then there will be a whitespace between the equal sign and the Taylor expansion on slide 2. - Using
\hphantom
with\alt
or\temporal
might be a solution but it seems very complicated to use it for more then two slides
Best Answer
There are a number of ways of doing this. Here's one, using
\phantom{<stuff>}
to pad the missing<stuff>
in the shorter equation:Placement of the
\phantom{<stuff>}
depends on how you want to examine the contents. For example, you could also tryAlso see
\temporal
in thebeamer
documentation.For larger constructions, the best offer I can make is to identify the biggest (horizontally and vertically) element in the set of equations and store these in a macro and use another macro as a space-adjustment:
If you have two separate equations that make up the "biggest", use a combination of
\vphantom
(for the tallest/deepest) and\hphantom
(for the widest/longest). Here's such an example: