我尝试在 Beamer 中两次更改 Tikz 节点的节点样式,但第二次更改未完成。我需要在 MWE 中修复哪些问题才能使其正常工作?
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}[label=fooFrame]{You Will Be Amazed.}
\tikzstyle{empty} = [shape=rectangle, draw=green, fill=green, inner sep=0pt, minimum size=4mm]
\tikzstyle{wip} = [shape=rectangle, draw=red, fill=red, inner sep=0pt, minimum size=4mm, label={center:?}]
\tikzstyle{done} = [shape=rectangle, thick, draw=blue!50, inner sep=0pt, minimum size=4mm, label={center:$\checkmark$}]
\tikzstyle{mynode} = [empty]
\only<2>{\tikzset{mynode/.style={wip}}}
\only<3>{\tikzset{mynode./style={done}}}
\begin{tikzpicture}
\node[mynode] {};
\end{tikzpicture}
\end{frame}
\end{document}
结果是,样式empty
应用于第一张幻灯片,样式wip
应用于第二张幻灯片,但随后empty
在最后一张幻灯片中再次应用,这正是我所期望done
出现的地方。
笔记:
- 另外,我无法在第一张幻灯片
\tikzstyle{}
中用 来代替。\tikzset
- 使用
\only<1>{...}
也无济于事。
答案1
有点语法错误。你有
\only<3>{\tikzset{mynode./style={done}}}
而且应该是
\only<3>{\tikzset{mynode/.style={done}}}
(点后斜线)。
完整代码(我将旧语法更改\tikzstyle
为\tikzset
):
\documentclass{beamer}
\usepackage{tikz}
\tikzset{
empty/.style = {shape=rectangle, draw=green, fill=green, inner sep=0pt, minimum size=4mm},
wip/.style = {shape=rectangle, draw=red, fill=red, inner sep=0pt, minimum size=4mm, label={center:?}},
done/.style = {shape=rectangle, thick, draw=blue!50, inner sep=0pt, minimum size=4mm, label={center:$\checkmark$}}
}
\begin{document}
\begin{frame}[label=fooFrame]{You Will Be Amazed.}
\tikzset{mynode/.style={empty}}
\only<2>{\tikzset{mynode/.style={wip}}}
\only<3>{\tikzset{mynode/.style={done}}}
\begin{tikzpicture}
\node[mynode] {};
\end{tikzpicture}
\end{frame}
\end{document}