4

[I'm sorry if this is a duplicate. I searched and found related issues but haven't been able to solve my problem.]

I have a displayed equation and I want to replace it with another in an overlay without affecting the surrounding text. As shown below, I've tried six different ways, but none of them works. The surrounding text is fixed, which is what I want, in the "uncover", "uncover&overprint", and "overprint&onslide" solutions below but the equation shifts. In the other solutions, the surrounding text shifts.

I know absolute text positioning via the textpos package is a solution but it's tedious. I also think that giving a fake height to the less tall equation via phantom would work, too.

But, I thought that a simple solution would be already there, seeing that uncover and overprint are able to fix the position of the surrounding text.

\documentclass[14pt,aspectratio=1609]{beamer}
\begin{document}
%----
\begin{frame}{only}
Fixed text
\only<1>{\[\int f(x)\]}%
\only<2>{\[g(x)\]}%
fixed text.
\end{frame}
%---
\begin{frame}{uncover}
Fixed text
\uncover<1>{\[\int f(x)\]}%
\uncover<2>{\[g(x)\]}%
fixed text.
\end{frame}
%---
\begin{frame}{uncover \& overprint}
Fixed text
\begin{overprint}
\uncover<1>{\[\int f(x)\]}%
\uncover<2>{\[g(x)\]}%
fixed text.
\end{overprint}
\end{frame}
%----
\begin{frame}{Overprint \& onslide}
Fixed text
\begin{overprint}
\onslide<1>{\[\int f(x)\]}%
\onslide<2>{\[g(x)\]}%
\end{overprint}
fixed text.
\end{frame}
%----
\begin{frame}{Overprint, only, \& onslide}
Fixed text
\begin{overprint}
\only<1>{\[\int f(x)\]}%
\onslide<2>{\[g(x)\]}%
\end{overprint}
fixed text.
\end{frame}
%----
\begin{frame}{alt}
Fixed text
\alt<2->%
{\[g(x)\]}%
{\[\int f(x)\]}%
fixed text.
\end{frame}
\end{document}
Ryo
  • 871

2 Answers2

3

The correct combination is overprint and \onslide. Note: the \onslide commands are used like \item commands (i.e. without argument).

\documentclass[14pt,aspectratio=1609]{beamer}
\begin{document}
\begin{frame}{Overprint \& onslide}
Fixed text
\begin{overprint}
  \onslide<1>
  \[\int f(x)\]

\onslide<2> [g(x)]
\end{overprint} fixed text. \end{frame} \end{frame} \end{document}

enter image description here

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
  • Thanks!!! Of course it works!! The only remaining question I have is, why is this? "the \onslide commands are used like \item commands (i.e. without argument)" There must be use cases where the item-like use is necessary. – Ryo May 15 '23 at 05:33
2

Perhaps the following is over-complicated for this one example, but if you do this often you might find the following approach useful, which defines a new command (from here: https://tex.stackexchange.com/a/63559/12212) for this purpose, Alt (note the capital 'A'):

\documentclass[14pt,aspectratio=1609]{beamer}

% https://tex.stackexchange.com/questions/13793/beamer-alt-command-like-visible-instead-of-like-only \usepackage{etoolbox} \makeatletter \newcommand<>\Alt[2]{{% \sbox0{$\displaystyle #1$}% \sbox1{$\displaystyle #2$}% \alt#3% {\rlap{\usebox0}\vphantom{\usebox1}\hphantom{\ifnum\wd0>\wd1 \usebox0\else\usebox1\fi}}% {\rlap{\usebox1}\vphantom{\usebox0}\hphantom{\ifnum\wd0>\wd1 \usebox0\else\usebox1\fi}}% }} \makeatother

\begin{document} \begin{frame}{only} Fixed text\bigskip{} [\Alt<2->{g(x)}{\int f(x)}]% fixed text. \end{frame} \end{document}

enter image description here

scottkosty
  • 13,164