32

I've got an underbrace (\underbrace{foo}_{bar}) which I want to uncover (i.e. foo should be there from the beginning, while the underbrace and the bar should be uncovered on the next slide. I've tried the following, which (not surprisingly) doesn't work:

\documentclass{beamer}

\begin{document}
\begin{frame}
  Without uncover (this is what it should look like on the second subframe):
  \begin{displaymath}
    \underbrace{foo}_{bar}
  \end{displaymath}
  With uncover (doesn't work):
  \begin{displaymath}
    \uncover<2>{\underbrace}{foo}\uncover<2>{_{bar}}
  \end{displaymath}
\end{frame}
\end{document}

In the second displaymath, the underbrace is displayed before foo and the bar as index to foo, and moreover the underbrace is immediately visible.

Note that \only wouldn't be a solution because on one hand in my actual document I use \setbeamercovered{transparent} so the underbrace and the text below should be lightly visible from the beginning, and on the other hand \only would also not keep the space for the underbrace.

So how can I achieve that?

21

One way to do that, is to use the definition of the transparency (15% Text foreground on the background and to avoid the “jumping” use as suggested here the overprint environment.

Though you have to define your term that's \underbraced twice and in my quick hack the transparency color is the one mentioned above, because i didn't find whether i can somehow get that by \usebeamercolor

\documentclass[transparent]{beamer}
\usepackage{amsmath}
\usepackage{cancel}
\begin{document}
    \setbeamercovered{transparent}
    \begin{frame}%
        \begin{overprint}
            \onslide<1>\begin{displaymath}
                \color{normal text.fg!15!normal text.bg}
                \underbrace{\usebeamercolor[fg]{text}foo}_{bar}
            \end{displaymath}
            \onslide<2>\begin{displaymath}
                \underbrace{foo}_{bar}
            \end{displaymath}
        \end{overprint}
    \end{frame}%
\end{document}

And (thanks to @Andrew Stacey) the even shorter version just switching colors using \only (because \color is sensitive to that) would be

\begin{frame}
    \begin{displaymath}
        \color{normal text.fg!15!normal text.bg}
        \only<2->{\color{normal text.fg}}
        \underbrace{\usebeamercolor[fg]{text}foo}_{bar}
    \end{displaymath}
\end{frame}
  • 2
    If you put the \color in an \only (or maybe \color is overlay-aware, I don't recall off-hand) then your first \underbrace part should render correctly on both slides, I think. – Loop Space Feb 14 '12 at 17:59
  • I added a shorter version of the frame based on your hint. – Ronny Feb 14 '12 at 21:45
  • 1
    The shorter version is perfect! – celtschk Feb 15 '12 at 10:27
  • Using \textcolor would be better if there are expressions after the term in the underbrace – Herr K. Jan 24 '13 at 1:29
20

Here's a solution that just uses \onslide (so that there's no need to know the precise definition of transparency):

\documentclass{beamer}
\setbeamercovered{transparent}
\begin{document}
\begin{frame}
    \begin{displaymath}
        \onslide<2-> \underbrace{ \onslide<1->
        foo
        \onslide<2-> }_{bar} \onslide<1->
        \text{some more stuff for slide 1}
    \end{displaymath}
\end{frame}
\end{document}
  • Looks hacky but otherwise a good solution! – varepsilon Oct 23 '16 at 15:03
10

Based on Hendrik Vogt's answer, and for my needs, I created these commands to make my life easier:

\newcommand<>{\uncoverubrace}[2]{%
  \onslide#3 \underbrace{ \onslide<1->%
  #1%
  \onslide#3 }_{#2} \onslide<1->%
}
\newcommand<>{\uncoverobrace}[2]{%
  \onslide#3 \overbrace{ \onslide<1->%
  #1%
  \onslide#3 }^{#2} \onslide<1->%
}

Now the use is very simple:

\usepackage{mathtools}
...
\begin{displaymath}
\uncoverubrace<2->{a_i}{\mathclap{\text{$N$ elements}}} =
\frac{
  \uncoverobrace<3->{b_j-b_i}{\mathclap{\text{$2N$ items needed}}}
}{2h}
\end{displaymath}

Room for improvement: allow relative overlay specifications (<+->).

  • Great solution! Easy to understand what is happening in the code and convenient to use. – usernumber Feb 20 at 14:24

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.