我想使用类似命令的方式在 Beamer 幻灯片中突出显示 tikz 图表的不同部分\only
。我能够在节点级别执行此操作,这可能没问题,但由于我有一些较长的节点定义,我想知道我是否可以将\only
其放在\node
例如
\node [block \only<1>{,fill=blue!50}] (start) {start};
不会起作用(这并不奇怪)。
下面发布的 MWE 可以解决我的问题,但我很好奇是否存在更原子的解决方案(即在命令内\node
而不是在命令外部工作)。我想如果我们仅限于乳胶,这是不可能的。
\documentclass[compress,red,notes]{beamer}
\usepackage{tikz}
\tikzstyle{line} = [draw, very thick, color=black!50]
\tikzstyle{block} = [rectangle, draw,
text centered, node distance=4em]
\begin{document}
\begin{frame}
\frametitle{An tikz diagram.}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.5, every node/.style={scale=0.5}]
\only<1>\node [block, fill=blue!50] (start) {start};
\only<2>\node [block] (start) {start};
\node [block, below of=start] (end) {end};
\path [line] (start) -- (end);
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
根据@Kevin C 的建议查看@Daniel 的回答,我得到以下不起作用的解决方案:
\documentclass[compress,red,notes]{beamer}
\usepackage{tikz}
\tikzstyle{line} = [draw, very thick, color=black!50]
\tikzstyle{block} = [rectangle, draw,
text centered, node distance=4em]
\tikzset{
invisible/.style={#1{}},
visible on/.style={alt={{color=blue!50}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
\begin{document}
\begin{frame}
\frametitle{An tikz diagram.}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.5, every node/.style={scale=0.5}]
\node [block, visible on=<2>] (start) {start};
\node [block, below of=start] (end) {end};
\path [line] (start) -- (end);
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
答案1
要设置某些键在指定的幻灯片上生效,您可以定义一个比 Daniel 的样式稍微简单一点的样式visible on
。以下onslide
样式定义就足够了:
% usage: onslide=<overlay spec>{keys}
onslide/.code args={<#1>#2}{\only<#1>{\pgfkeysalso{#2}}}
代码
\documentclass[compress,red,notes]{beamer}
\usepackage{tikz}
\tikzset{
line/.style={draw, very thick, color=black!50},
block/.style={rectangle, draw, text centered, node distance=4em},
onslide/.code args={<#1>#2}{\only<#1>{\pgfkeysalso{#2}}},
}
\begin{document}
\begin{frame}
\frametitle{An tikz diagram.}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.5, every node/.style={scale=0.5}]
\node [block, onslide=<2>{fill=blue!50}] (start) {start};
\node [block, below of=start] (end) {end};
\path [line] (start) -- (end);
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}