3

I need to use \onslide and \underbrace within brackets [] that are raised to an exponent. However, when I use \onslide, the exponent is not displayed properly. Is there a way to fix this? Below is a code comparing with and without \onslide.

\documentclass[english]{beamer}
\begin{document}

\begin{frame}
\begin{align*}
\left[             \underbrace{A}_{Text} + B \right]^{C} % Works: Power C   correctly displayed
\\ \\
 \left[ \onslide<1> \underbrace{A}_{Text} + B \right]^{C} % Does not work: Power  C not correctly displayed
\end{align*}
\end{frame}

\end{document}
  • You want something like this: \onslide<1>{\left[\underbrace{A}_{Text} + B \right]^{C}}? – Benjamin Mar 25 '16 at 17:53
  • Thanks. No, I need the \onslide right before the \underbrace. I use it to only show the \underbrace on select slides. This was just a MWE to show how \onslide was messing up the display of the exponent. – user3904282 Mar 25 '16 at 18:17
  • So more something like this: \left[ \alt<2>{\underbrace{A}_{Text}}{A} + B \right]^{C} – Benjamin Mar 25 '16 at 18:28
  • Thanks, I did not know about \alt. That works, but it doesn't keep the spacing consistent throughout the slide. Is there a way to use \alt where the spacing doesn't jump around? – user3904282 Mar 25 '16 at 18:37
  • 1
    That is a bit tricky, but is possible. Have a look at this SE question: tex.stackexchange.com/questions/13793/… – Benjamin Mar 25 '16 at 18:50
3

As Benjamin pointed out, correct placement of the exponent and consistent spacing inside the brackets can be achieved using Henry DeYoung's answer for "Beamer alt command like visible instead of like only":

\documentclass[english]{beamer}

% Beamer alt command like visible instead of like only (answer by Henry DeYoung)
% (https://tex.stackexchange.com/a/63559)
\usepackage{etoolbox}
\usepackage{mathtools}

\makeatletter
% Detect mode. mathpalette is used to detect the used math style
\newcommand<>\Alt[3][l]{%
  \begingroup
    \providetoggle{Alt@before}%
    \alt#4{\toggletrue{Alt@before}}{\togglefalse{Alt@before}}%
    \ifbool{mmode}{%
      \expandafter\mathpalette
      \expandafter\math@Alt
    }{%
      \expandafter\make@Alt
    }%
    {{#1}{#2}{#3}}%
  \endgroup
}

% Un-brace the second argument (required because \mathpalette reads the three arguments as one
\newcommand\math@Alt[2]{\math@@Alt{#1}#2}

% Set the two arguments in boxes. The math style is given by #1. \m@th sets \mathsurround to 0.
\newcommand\math@@Alt[4]{%
  \setbox\z@ \hbox{$\m@th #1{#3}$}%
  \setbox\@ne\hbox{$\m@th #1{#4}$}%
  \@Alt{#2}%
}

% Un-brace the argument
\newcommand\make@Alt[1]{\make@@Alt#1}

% Set the two arguments into normal boxes
\newcommand\make@@Alt[3]{%
  \sbox\z@ {#2}%
  \sbox\@ne{#3}%
  \@Alt{#1}%
}

% Place one of the two boxes using \rlap and place a \phantom box with the maximum of the two boxes
\newcommand\@Alt[1]{%
  \setbox\tw@\null
  \ht\tw@\ifnum\ht\z@>\ht\@ne\ht\z@\else\ht\@ne\fi
  \dp\tw@\ifnum\dp\z@>\dp\@ne\dp\z@\else\dp\@ne\fi
  \wd\tw@\ifnum\wd\z@>\wd\@ne\dimexpr\wd\z@/2\relax\else\dimexpr\wd\@ne/2\relax\fi
  %
  \ifstrequal{#1}{l}{%
    \rlap{\iftoggle{Alt@before}{\usebox\z@}{\usebox\@ne}}%
    \copy\tw@
    \box\tw@
  }{%
    \ifstrequal{#1}{c}{%
      \copy\tw@
      \clap{\iftoggle{Alt@before}{\usebox\z@}{\usebox\@ne}}%
      \box\tw@
    }{%
      \ifstrequal{#1}{r}{%
        \copy\tw@
        \box\tw@
        \llap{\iftoggle{Alt@before}{\usebox\z@}{\usebox\@ne}}%
      }{%
      }%
    }%
  }%
}
\makeatother

\begin{document}

\begin{frame}<1-2>
\begin{align*}
    \left[ \Alt<1>[c]{\underbrace{\only<*>{A}}_{Text}}{A} + B \right]^{C}
\end{align*}
\end{frame}

\end{document}

slide 1, with underbrace shown

slide 2, with underbrace hidden (but spacing retained)

| improve this answer | |

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.