Beamer/TikZ/PGF:仅为一张幻灯片应用一个键(类似于发现或仅)

Beamer/TikZ/PGF:仅为一张幻灯片应用一个键(类似于发现或仅)

我想要一个只在特定幻灯片/帧中应用的键,就像uncoveronly。以下是示例:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\begin{frame}

  \begin{tikzpicture}
    \draw [fill=orange] (0,0) rectangle (1,1);
    \uncover<1>{\node at (2,0) [anchor=west] {1};}
    \uncover<2>{\node at (2,0) [anchor=west] {2 -- should be only orange here};}
    \uncover<3>{\node at (2,0) [anchor=west] {3};}
  \end{tikzpicture}

\end{frame}

\end{document} 

输出如下所示:

enter image description here enter image description here enter image description here

问题

例如,我希望填充键仅应用于第二帧 - 如下所示:fill=<2>orange

我试图理解相关问题,但接受答案的代码对我来说太复杂了。但我猜这与它有关。

有任何想法吗?

答案1

您可以定义使用覆盖规范的样式:

\documentclass{beamer}
\usepackage{tikz}

\tikzset{onslide/.code args={<#1>#2}{%
  \only<#1>{\pgfkeysalso{#2}} % \pgfkeysalso doesn't change the path
}}

\begin{document}

\begin{frame}

  \begin{tikzpicture}
    \draw [onslide=<2>{fill=orange}] (0,0) rectangle (1,1);
    \uncover<1>{\node at (2,0) [anchor=west] {1};}
    \uncover<2>{\node at (2,0) [anchor=west] {2 -- should be only orange here};}
    \uncover<3>{\node at (2,0) [anchor=west] {3};}
  \end{tikzpicture}

\end{frame}

\end{document}

enter image description here

答案2

一个特别直接的方法就是使用\tikzsetinside \only

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}
  \begin{tikzpicture}
    \only<2>{\tikzset{every path/.style={fill=orange}}}
    \draw (0,0) rectangle (1,1);
    \uncover<1>{\node at (2,0) [anchor=west] {1};}
    \uncover<2>{\node at (2,0) [anchor=west] {2 -- should be only orange here};}
    \uncover<3>{\node at (2,0) [anchor=west] {3};}
  \end{tikzpicture}
\end{frame}    
\end{document}

或者,您可以定义一个覆盖感知版本\tikzset

\documentclass{beamer}
\usepackage{tikz}
\renewcommand<>\tikzset[1]{\only#2{\beameroriginal{\tikzset}{#1}}}
\begin{document}
\begin{frame}
  \begin{tikzpicture}
    \tikzset<2>{every path/.style={fill=orange}}
    \draw (0,0) rectangle (1,1);
    \uncover<1>{\node at (2,0) [anchor=west] {1};}
    \uncover<2>{\node at (2,0) [anchor=west] {2 -- should be only orange here};}
    \uncover<3>{\node at (2,0) [anchor=west] {3};}
  \end{tikzpicture}
\end{frame}    
\end{document}

两个版本的功能相同,但如果您需要经常使用,后者会稍微方便一些。

答案3

另一种方法是使用aobs-tikz定义适合覆盖层的 TikZ 样式的包:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}

\begin{document}

\begin{frame}

  \begin{tikzpicture}
    \draw [background fill=orange,fill on=<2>] (0,0) rectangle (1,1);
    \node[visible on=<1>] at (2,0) [anchor=west] {1};
    \node[visible on=<2>]  at (2,0) [anchor=west] {2 -- should be only orange here};
    \node[visible on=<3>]  at (2,0) [anchor=west] {3};
  \end{tikzpicture}

\end{frame}

\end{document}

结果:

enter image description here

相关内容