1

Consider the following slide:

\documentclass{beamer}

\mode<presentation> {
\usetheme{Madrid}
\usecolortheme[RGB={0,0,0}]{structure}
}

\usepackage{amsmath,amsfonts,graphicx}
\usepackage{algpseudocode}
\usepackage{tikz, nth}

\usetikzlibrary{arrows.meta,decorations,decorations.pathreplacing,calc,bending,positioning, chains}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{document}
\begin{frame}
\frametitle{Example: AVL Trees}
\uncover<+->{{\bf Solution: \\~\\}
\uncover<+->{{\bf Recall:} The balance factor of a node is equal to the height of the right subtree minus the height of the left subtree. \\~\\}
\begin{minipage}{1.0\linewidth}
\begin{center}
\uncover<+->{
\begin{tikzpicture}[%
  level distance=15 pt,
  every node/.style={circle,draw,font=\scriptsize},
  level 1/.style={sibling distance=150 pt},
  level 2/.style={sibling distance=70 pt},
  level 3/.style={sibling distance=60 pt}%
]
  \node {{\uncover<8->{-1}}}
    child {node {{\uncover<7->{-1}}}
      child {node {{\uncover<6->{1}}}
        child {node {{\uncover<4->{0}}}}
        child {node {{\uncover<5->{0}}}
          child {node {{\uncover<4->{0}}}}
          child {node {{\uncover<4->{0}}}}
        }
      }
      child {node {{\uncover<7->{1}}}
        child {edge from parent[draw=none]}
        child {node {{\uncover<4->{0}}}}
      }
    }
    child {node {{\uncover<6->{1}}}
      child {node {{\uncover<4->{0}}}}
      child {node {{\uncover<5->{-1}}}
        child {node {{\uncover<4->{0}}}}
        child {edge from parent[draw=none]}
      }
    }
  ;
\end{tikzpicture}}
\end{center}
\end{minipage}
}
\end{frame}
\end{document}

I would like to add a fill color option to the nodes that are currently being uncovered. So for example, when I uncover those with <4->, I want them to be red. But when I uncover the next ones <5->, I do not what the <4-> to be red anymore, just the newly uncovered ones. Likewise when I uncover <6-> and so forth. What's the easiest way to do this? I can't get them to change back after setting them to be red.

1

You could use \alert<>{} to specify the slides on which the text should be shown 'alerted'. By default, this happens to be red.

For example (and simplifying the code and MWE a bit):

\documentclass{beamer}
\mode<presentation>
{
  \usetheme{Madrid}
  \usecolortheme[RGB={0,0,0}]{structure}
}
\usepackage{amsmath,amsfonts}
\usepackage{tikz}

\begin{document}
\begin{frame}
  \frametitle{Example: AVL Trees}
  \onslide<+->
  \textbf{Solution:}
  \bigskip\par
  \onslide<+->
  \textbf{Recall:} The balance factor of a node is equal to the height of the right subtree minus the height of the left subtree.
  \bigskip\par
  \begin{center}
    \onslide<+->
    \begin{tikzpicture}[%
      level distance=15 pt,
      every node/.style={circle,draw,font=\scriptsize},
      level 1/.style={sibling distance=150 pt},
      level 2/.style={sibling distance=70 pt},
      level 3/.style={sibling distance=60 pt}%
      ]
      \node {{\uncover<8->{\alert<8>{-1}}}}
      child {node {{\uncover<7->{\alert<7>{-1}}}}
        child {node {{\uncover<6->{\alert<6>{1}}}}
          child {node {{\uncover<4->{\alert<4>{0}}}}}
          child {node {{\uncover<5->{\alert<5>{0}}}}
            child {node {{\uncover<4->{\alert<4>{0}}}}}
            child {node {{\uncover<4->{\alert<4>{0}}}}}
          }
        }
        child {node {{\uncover<7->{\alert<7>{1}}}}
          child {edge from parent[draw=none]}
          child {node {{\uncover<4->{\alert<4>{0}}}}}
        }
      }
      child {node {{\uncover<6->{\alert<6>1}}}
        child {node {{\uncover<4->{\alert<4>{0}}}}}
        child {node {{\uncover<5->{\alert<5>{-1}}}}
          child {node {{\uncover<4->{\alert<4>{0}}}}}
          child {edge from parent[draw=none]}
        }
      }
      ;
    \end{tikzpicture}
  \end{center}
\end{frame}
\end{document}

alerted nodes in tree

I'd use Forest for the tree, but you can do without it 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.