Sometimes I want an element on a frame to change in steps. I do this by
\only<2>{
...
}
\only<3>{
...
}
etc.
But this causes the frame to jump due to different sizes of the included content. How can this be avoided?
This issue is addressed in the beamer
manual in section 9.5 Dynamically Changing Text or Images, p.85 for v.3.10.
You need to use either the overlayarea
environment which is "more flexible but less user friendly" or the overprint
environment.
\begin{overlayarea}{⟨area width⟩}{⟨area height⟩}
⟨environment contents⟩
\end{overlayarea}
\begin{overprint}[⟨area width⟩]
⟨environment contents⟩
\end{overprint}
You then need to use \onslide<⟨num⟩>
instead of \only<⟨num⟩>{...}
.
The numbers must be disjoint.
Example:
\begin{overprint}
% on every slide (not sure if it is officially supported)
\onslide<1>
% on first slide
\onslide<2>
% on slide two
\onslide<3>
% on slide three
% etc.
\end{overprint}
\only
within either an overprint
or overlayarea
environment seems to work fine. Also, \onslide
doesn't behave the same as \only
, so sometimes \only
may be preferred.
\only
does not work as intended. Also, very important is to not use braces around onlide
's "arguments" (even if they are necessary for the same construct in overlayarea
). Using braces makes the elements not overlap at all as they should.
overlayarea
with only
. Is it possible to make overlayarea
choose its own area height, which should be equal to the height of the longest only<>
entry?
The jumping occurs because beamer normally vertically centres the content on the frame.
One way to achieve a constant starting point for content of all heights(*) is to tell beamer to top align the frame. This can either be done on a frame-by-frame basis with
\begin{frame}[t]
or globally for the whole presentation:
\documentclass[t]{beamer}
MWE:
\documentclass{beamer}
\begin{document}
\begin{frame}[t]
\only<1>{abc}
\only<2>{abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc }
\end{frame}
\end{document}
(*) at least for all heights which don't overflow the available text height.
When dealing with figures, it can be sufficient to use \tikz[overlay]
inside \only
:
\only<.>{
\tikz[overlay,xshift=0em,yshift=0ex]{\draw node {
% content goes here
};}
}
Use a command phantom to build a same size of the elements.
\only<2>{
...
}
\only<2>{
\phantom{xxxx}
}
\only<3>{
xxxx
}
It seems that encapsulating the content of each step in textblocks often solves the problem of jumping frames. This is an example for a frame:
\begin{frame}
\only<1->
{
\begin{textblock*}{100mm}(10mm,0.2\textheight)
% first content
\end{textblock*}
}
\only<2->
{
\begin{textblock*}{100mm}(10mm,0.5\textheight)
% second content
\end{textblock*}
}
\end{frame}
%
characters ;-)