下面的最小示例可编译:
\documentclass[c]{beamer}
\usepackage{tikz,times}
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
},
}
\begin{document}
\begin{frame}[fragile]
\begin{tikzpicture}
\tikzstyle{StateNormal} = [fill=white]
\tikzstyle{StateSelected} = [fill=orange]
\coordinate (ONE) at (0,0);
\coordinate (TWO) at (4,0);
\coordinate (THREE) at (8,0);
\draw (ONE) -- (TWO) -| (THREE);
\draw
node at (ONE) [StateSelected, visible on=<1>]{ONE}
node at (ONE) [StateNormal, visible on=<2->]{ONE}
node at (TWO) [StateSelected, visible on=<2>]{TWO}
node at (TWO) [StateNormal, visible on=<3->]{TWO}
node at (THREE) [StateSelected, visible on=<3>]{THREE}
node at (THREE) [StateNormal, visible on=<4->]{THREE}
;
\end{tikzpicture}
%DO NOT INDENT THE END OF A FRAGILE FRAME
\end{frame}
\end{document}
我对这个例子有几个问题,但我不知道如何解决它们:
我只定义每个节点两次,因此它在不同的幻灯片上具有不同的属性。那里有冗余,我所知道的修复方法是使用新命令。这似乎是一个常见问题 - 还有其他标准解决方案吗?
node at (ONE) [StateSelected, visible on=<1>]{ONE}
node at (ONE) [StateNormal, visible on=<2->]{ONE}
我的下一个问题是数字之间总是存在联系。如果我想在前端插入幻灯片,我必须重命名从那里到末尾的所有幻灯片。
node at (ONE) [StateSelected, visible on=<1>]{ONE}
node at (ONE) [StateNormal, visible on=<2->]{ONE}
node at (TWO) [StateSelected, visible on=<2>]{TWO}
node at (TWO) [StateNormal, visible on=<3->]{TWO}
node at (THREE) [StateSelected, visible on=<3>]{THREE}
node at (THREE) [StateNormal, visible on=<4->]{THREE}
如果我在这里插入,这将创建一个需要大量重命名工作的新列表。
node at (ZERO) [StateSelected, visible on=<1>]{ZERO}
node at (ZERO) [StateNormal, visible on=<2->]{ZERO}
node at (ONE) [StateSelected, visible on=<2>]{ONE}
node at (ONE) [StateNormal, visible on=<3->]{ONE}
node at (TWO) [StateSelected, visible on=<3>]{TWO}
node at (TWO) [StateNormal, visible on=<4->]{TWO}
node at (THREE) [StateSelected, visible on=<4>]{THREE}
node at (THREE) [StateNormal, visible on=<5->]{THREE}
我想写:
count = 1;
node at (ZERO) [StateSelected, visible on=<(count)>]{ZERO}
node at (ZERO) [StateNormal, visible on=<(count+1)->]{ZERO}
count ++;
node at (ONE) [StateSelected, visible on=<(count)>]{ONE}
node at (ONE) [StateNormal, visible on=<(count+1)->]{ONE}
count ++;
node at (TWO) [StateSelected, visible on=<(count)>]{TWO}
node at (TWO) [StateNormal, visible on=<(count+1)->]{TWO}
count ++;
node at (THREE) [StateSelected, visible on=<(count)>]{THREE}
node at (THREE) [StateNormal, visible on=<(count+1)->]{THREE}
但我不知道如何在 MikTex 中写这样的语句。
答案1
您可以使用\temporal
而不是\alt
来指定“之前”,“幻灯片上”和“之后”样式,并直接使用它来避免节点重复。
为了避免幻灯片编号的硬编码,只需使用特殊覆盖规范+
,这意味着“插入新幻灯片并将新幻灯片作为规范的参考”:
\documentclass[c]{beamer}
\usepackage{tikz,times}
\tikzset{
invisible/.style={opacity=0},
temporal/.code args={<#1>#2#3#4}{
\temporal<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}{\pgfkeysalso{#4}}
},
}
\begin{document}
\begin{frame}[fragile]
\begin{tikzpicture}
\tikzstyle{StateNormal} = [fill=white]
\tikzstyle{StateSelected} = [fill=orange]
\coordinate (ONE) at (0,0);
\coordinate (TWO) at (4,0);
\coordinate (THREE) at (8,0);
\draw (ONE) -- (TWO) -| (THREE);
\draw
node at (ONE) [temporal=<+>{invisible}{StateSelected}{StateNormal}]{ONE}
node at (TWO) [temporal=<+>{invisible}{StateSelected}{StateNormal}]{TWO}
node at (THREE) [temporal=<+>{invisible}{StateSelected}{StateNormal}]{THREE}
;
\end{tikzpicture}
%DO NOT INDENT THE END OF A FRAGILE FRAME
\end{frame}
\end{document}
您甚至可以通过定义以下样式使语法更具可读性:
\tikzset{
invisible/.style={opacity=0},
normal/.style={fill=white},
selected/.style={fill=orange},
temporal/.code args={<#1>#2#3#4}{%
\temporal<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}{\pgfkeysalso{#4}}
},
change style/.code args={start #1 then on <#2> to #3 and after to #4}{\temporal<#2>{\pgfkeysalso{#1}}{\pgfkeysalso{#3}}{\pgfkeysalso{#4}}},
reveal on/.style={change style=start invisible then on #1 to selected and after to normal},
reveal/.style={reveal on=<+>}
}
你的代码变成了
\draw
node at (ONE) [reveal]{ONE}
node at (TWO) [reveal]{TWO}
node at (THREE) [reveal]{THREE}
;
如果您希望在幻灯片 2 上显示某些内容,则可以使用样式reveal on=<2>
,如果您希望仅在幻灯片 3 和幻灯片 5 之间显示某些内容,则可以执行此操作change style=start invisible then on <3-5> to normal and after to invisible
。