题
这就是我要做的
\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}
问题是
\node [selected] (nodeB) {};
创建一个新的节点,但我希望它为现有节点应用样式。有什么办法吗?
当然,我可以在选定状态和未选择状态的每个节点中拥有每个节点的副本,但是我真的想拥有一个普通的解决方案。
解决方案
我认为您无法按照自己的意愿进行操作(假设我正确理解了这个问题),因为一旦绘制了节点,就无法更改其外观。我建议使用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}};
或类似的东西(您可能必须修补半洛龙才能使它起作用,目前我无法测试它)。
另一个选择是实际上只是绘制一个新节点。如果包括
\node[module,selected] at (nodeA) {node A};
里面 \only<2>
, ,这将绘制一个看起来像节点A的节点,除了红色背景,在节点A处的同一位置。新节点将覆盖原始节点A。
其他提示
有时,为了避免重复,做这样的事情可能很不错:
% #1 Overlay specs.
% #2 Style name.
% #4 Style properties.
\def\onlystyle<#1>#2#3{%
\alt<#1>{%
\tikzset{#2/.style = {#3}}
}{%
\tikzset{#2/.style = {}}
}%
}
然后,如果将其放在框架内,则应说明:
\onlystyle<2>{selected}{fill = red}
样式 selected
将定义为 fill = red
在动画的第二个幻灯片上,作为一种对其他幻灯片的效果没有任何影响的样式。然后,您可以编写一个可读的数字,例如:
\begin{tikzpicture}
\node at (0, 0) {A};
\node[selected] at (1, 0) {B};
\node at (2, 0) {C};
\end{tikzpicture}
第二幻灯片将突出显示“ B”节点。这样,您不必复制大量节点定义。当然,它不能应用于每个动画需求,但我喜欢将这种技术保持在袖子上。
不隶属于 StackOverflow