请考虑以下幻灯片:
\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}
我想为当前未被覆盖的节点添加填充颜色选项。例如,当我覆盖那些带有 <4-> 的节点时,我希望它们变成红色。但是当我覆盖下一个节点 <5-> 时,我不再希望 <4-> 是红色,只希望新覆盖的节点是红色。当我覆盖 <6-> 等节点时也是如此。最简单的方法是什么?将它们设置为红色后,我无法让它们变回红色。
答案1
您可以使用\alert<>{}
来指定应在哪些幻灯片上显示“警告”文本。默认情况下,它显示为红色。
例如(稍微简化代码和 MWE):
\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}
我会使用 Forest 来表示树,但是在这里你可以不用它 ;)。