2

I'm trying to show an equation that has two components. For each component, I would like to explain each term one by one, so was able to use \underbrace to uncover component by component following this link. The problem is that I can't uncover the corresponding plot in the tikzpicture one by one (they all appear at the end.

In other words, the first figure should appear together with the first underbrace, and similarly with the second underbrace. Is this an issue on my definition of visible in tiksset or it simply can't be done?

\documentclass[xcolor={dvipsnames,table}, fleqn]{beamer}
\usefonttheme{professionalfonts}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots, backgrounds, plotmarks, calc, spy, pgfplots.polar, shapes.geometric, arrows, external, patterns}


\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }

\begin{document}

\begin{frame}

\[ x  = \onslide<2-> \underbrace{ \onslide<1-> a \onslide<2-> }_{\text{(A)}}  \onslide<1-> -  \onslide<3-> \underbrace{  \onslide<1->b \onslide<3-> }_{\text{(B)}} \]

\begin{figure}
  \centering
    \begin{tikzpicture}

    \begin{groupplot}[
        group style={
            group size=1 by 3,
        },
        unit vector ratio*=1 1 1,
        xmin=-1.5,xmax=1.5,
        ymin=0,ymax=1.8,
        width = 4cm,
        axis line style={draw=none},
        xmajorticks=false,
        ymajorticks=false
        ]

    \nextgroupplot[]

    \addplot [visible on=<2->, thick,color=black,mark=none,fill=black, 
                fill opacity=0.05] coordinates {
        (-1.5,0)  (-1.5,1.5)  (-0.5, 0.5) (0.5, 0.) (1.5, 1.5) (1.5,0) };

    \nextgroupplot[]

    \addplot [visible on=<3->, thick,color=black,mark=none,fill=black, 
                fill opacity=0.05] coordinates {
        (-1.5,0)  (-1.5,1.5) (-0.5,0) (0.5,0) (1.5, 1.5) (1.5,0) };

    \nextgroupplot[ymax=1]

    \addplot [thick,color=black,mark=none,fill=black, 
                fill opacity=0.05] coordinates {
        (-0.5, 0) (-0.5,0.5) (0.5,0)};

    \end{groupplot}    
    \end{tikzpicture}

\end{figure}

\end{frame}

\end{document}
2

The problem comes from you \onslide construction. You had an \onslide<3-> at its end such that everything after only appears from slide 3 on. To cure that, you only need to add an \onslide<1-> after the equation. I also changed the filling to black!5 as your opacity directive overrides the opacity=0 trick that is used to make the plots invisible on the early slides.

\documentclass[xcolor={dvipsnames,table}, fleqn]{beamer}
\usefonttheme{professionalfonts}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots, backgrounds, plotmarks, calc, spy, pgfplots.polar, shapes.geometric, arrows, external, patterns}


\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }

\begin{document}

\begin{frame}

\[ x  = \onslide<2-> \underbrace{ \onslide<1-> a \onslide<2-> }_{\text{(A)}}  \onslide<1-> -  \onslide<3-> \underbrace{  \onslide<1->b \onslide<3-> }_{\text{(B)}} \]
\onslide<1->

\begin{figure}
  \centering
    \begin{tikzpicture}

    \begin{groupplot}[
        group style={
            group size=1 by 3,
        },
        unit vector ratio*=1 1 1,
        xmin=-1.5,xmax=1.5,
        ymin=0,ymax=1.8,
        width = 4cm,
        axis line style={draw=none},
        xmajorticks=false,
        ymajorticks=false
        ]

    \nextgroupplot[]

    \addplot [visible on=<2->, thick,color=black,mark=none,fill=black!5] coordinates {
        (-1.5,0)  (-1.5,1.5)  (-0.5, 0.5) (0.5, 0.) (1.5, 1.5) (1.5,0) };

    \nextgroupplot[]

    \addplot [visible on=<3->, thick,color=black,mark=none,fill=black!5] coordinates {
        (-1.5,0)  (-1.5,1.5) (-0.5,0) (0.5,0) (1.5, 1.5) (1.5,0) };

    \nextgroupplot[ymax=1]

    \addplot [thick,color=black,mark=none,fill=black!5] coordinates {
        (-0.5, 0) (-0.5,0.5) (0.5,0)};

    \end{groupplot}    
    \end{tikzpicture}

\end{figure}

\end{frame}

\end{document}

enter image description here

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.