6

Hello and thank you in advance for your help!

I'm comparing the following two commands:

  1. This is a \only<1>{test}\only<2>{\textcolor{red}{test}}.

  2. $\only<1>{\max_{(x,y)}}\only<2>{\textcolor{red}{\max_{(x,y)}}}$

The first one works fine, and makes the text turn red.

The second one also makes the text turn red. However, it causes a small shift in the spacing. I can't figure out what is causing this shift, has anyone else run into this problem before?

Is it problems with the math environment?

  • 1
    I suspect that $\only<1>{...}$ leaves some empty box at the start of the math formula, so \max is slightly displaced because it's a math operator following an (empty) ordinary symbol. The same doesn't happen with \max inside \textcolor, because this starts another level of grouping and \max is the first item in the subformula. – egreg May 30 '13 at 23:07
  • What about \alert<2>{$\max_{(x,y)}$}? – Corentin May 30 '13 at 23:08
8

Please always post complete documents not just fragments.

The whatsit nodes needed for \only cause math atoms in math mode that can affect the spacing. Easiest is to put an empty math atom {} before the \max in both cases.

\documentclass{beamer}
\begin{document}

\begin{frame}{}

    This is a \only<1>{test}\only<2>{\textcolor{red}{test}}.

    $\only<1>{{}\max_{(x,y)}}\only<2>{\textcolor{red}{{}\max_{(x,y)}}}$

\end{frame}

\end{document}
4

Another option is to use math mode for each expression separately (this seems (at least to me) more syntactically correct):

\documentclass{beamer}
\begin{document}

\begin{frame}

This is a \only<1>{test}\only<2>{\textcolor{red}{test}}.

\only<1>{$\max_{(x,y)}$}\only<2>{\textcolor{red}{$\max_{(x,y)}$}}

\end{frame}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.