2

Please consider the following MWE:

\documentclass{beamer}

\usetheme{Copenhagen}

\begin{document}

\begin{frame} \begin{block}{} Text. \begin{align} A&=B\ \only<2>{ &\color{red}{C=D+1-5M\implies E=1}\ } \uncover<3->{&=C\} \uncover<4->{&=B} \end{align} \end{block} \end{frame}

\end{document}

The problem is on slide 2, where A=B is not in the same position as in slides 1, 3 and 5:

MWE output

I want the red because is a note for a property that I will use in the next step, however it is the only slide that is not aligned with respect to the others.

I would like to have the following output (see slide 2.):

What I want

How can we achieve the last image not using commands like \hspace?

manooooh
  • 3,203
  • 2
  • 21
  • 46

1 Answers1

2

In order for the elements to stop flickering between slides, they need to have the same width. One can assure they have the same width by using components from eqparbox (with a modification to allow for math content via \eqmathbox[<tag>][<align>]{<stuff>}). Additionally, I use \alt<os>{<default>}{<other>} which puts <default> on the provided overlay specification and <other> otherwise.

enter image description here

\documentclass{beamer}

\usetheme{Copenhagen} \usepackage{eqparbox} %\usepackage{xparse}% If you have LaTeX2e < 2020-10-01

% https://tex.stackexchange.com/a/34412/5764 \makeatletter % \eqmathbox[<tag>][<align>]{<math>} \NewDocumentCommand{\eqmathbox}{o O{c} m}{% \IfValueTF{#1} {\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}} {\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}} \mathpalette\eqmathbox@{#3} } \makeatother \begin{document}

\begin{frame}

\begin{block}{} Text. \begin{align} \eqmathbox[LHS][r]{A} &\eqmathbox[RHS][l]{{} = B} \ \alt<2>{\eqmathbox[LHS][r]{\color{red}C = D + 1}}{} & \alt<2>{\eqmathbox[RHS][l]{\color{red}{} - 5M \implies E = 1}}{\uncover<3->{= C}} \ \uncover<4->{&= D} \end{align} \end{block}

\end{frame}

\end{document}

Werner
  • 603,163
  • Thanks for the answer! It seems that my LaTeX distribution is having some issues with respect to eqparbox. I use pdfLaTeX. In Overleaf it throws me a lot of errors, and in TeXworks says: "! Undefined control sequence. l.29 \NewDocumentCommand {\eqmathbox}{o O{c} m}{%" – manooooh Mar 04 '21 at 21:25
  • 1
    @manooooh add \usepackage{xparse} for older releases. (as Werner has already put in a comment in the code) – David Carlisle Mar 04 '21 at 21:28