这就是我想要做的
\begin{tikzpicture}
[node distance = 1cm, auto,font=\footnotesize,
% STYLES
every node/.style={node distance=1.3cm},
comment/.style={rectangle, inner sep= 5pt, text width=4cm, node distance=0.25cm, font=},
module/.style={rectangle, drop shadow, draw, fill=black!10, inner sep=5pt, text width=3cm, text badly centered, minimum height=0.8cm, font=\bfseries\footnotesize\sffamily,rounded corners},
selected/.style={fill=red!40}]
\node [module] (nodeA) {node A};
\node [module, below of=nodeA] (nodeA) {node B};
\only<1>{
\node [comment, text width=6cm, right=0.25 of nodeA] {short description of Node A};
\node [comment, text width=6cm, right=0.25 of nodeB] {short description of Node B};
}
\only<2>{
\node [selected] (nodeA) {};
\node [comment, text width=6cm, right=0.25 of nodeA] {long description of node A};
}
\only<3>{
\node [selected] (nodeB) {};
\node [comment, text width=6cm, right=0.25 of nodeA] {long description of node B};
}
\end{tikzpicture}
Run Code Online (Sandbox Code Playgroud)
问题是
\node [selected] (nodeB) {};
Run Code Online (Sandbox Code Playgroud)
创建一个新节点,但我希望它为现有节点应用样式.有没有办法这样做?
当然,我可以拥有处于选定状态和未选择状态的每个节点的副本,但我真的想要一个正常的解决方案.
我认为您不能按照您想要的方式执行此操作(假设我正确理解问题),因为一旦绘制了节点,就无法更改其外观。我建议使用 Beamer 的\alt宏:
\alt<2>{\node[module,selected] at (nodeA) {node A};}{\node[module] at (nodeA) {node A};}
\alt<3>{\node[module,selected] at (nodeB) {node B};}{\node[module] at (nodeB) {node B};}
\node[comment,text width=6cm,right=0.25 of nodeA]{\alt<2>{short description}{long description}};
\node[comment,text width=6cm,right=0.25 of nodeB]{\alt<3>{short description}{long description}};
Run Code Online (Sandbox Code Playgroud)
或者类似的东西(你可能需要修改分号才能让它工作,我目前无法测试)。
另一种选择是实际上只绘制一个新节点。如果你包括
\node[module,selected] at (nodeA) {node A};
Run Code Online (Sandbox Code Playgroud)
inside \only<2>,这将在节点 A 的相同位置绘制一个与节点 A 类似的节点,除了红色背景之外。新节点将覆盖原始节点 A。