将间谍与 Beamer 动画一起使用?

将间谍与 Beamer 动画一起使用?

TikZ spy 和 Beamer \pause、\onslide 等似乎不能很好地协同工作。这在之前的几个问题中已经观察到,尽管这些问题比较老(特别是,12),但那里显示的解决方法对我来说不起作用。

M(N)WE:

\documentclass[tikz]{beamer}

\usepackage{tikz}
\usetikzlibrary{spy}


% following https://tex.stackexchange.com/questions/88251/tikz-spy-and-beamer-uncover and  https://tex.stackexchange.com/questions/438218/beamer-uncover-magnification-using-tikz-spy-library: 

\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    connect on/.style={alt={#1{connect spies}{}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} 
    },
}



\begin{document}

\begin{frame}
  \frametitle{test}

  \begin{tikzpicture}[spy using outlines={magnification=4, size=2cm, connect spies}]
    \node (first) {Initial text};

    % simple approach fails:
    \onslide <2->
    \spy on (first) in node at (2,-2);

    % this fails as well: https://tex.stackexchange.com/questions/88251/tikz-spy-and-beamer-uncover
    % \only<2->{
    %   \spy[overlay] on (first) in node at (2,-2);
    % }
    
    % approach inspired by https://tex.stackexchange.com/questions/438218/beamer-uncover-magnification-using-tikz-spy-library
    % fails as well
    % \spy[visible on=<2->] on (first) in node at (2,-2);
    % rewording as fails: 
    % \spy[connect on=<2->] on (first) in node[visible on=<2->] at (2,-2);
    
    % spy does not seem to be overlay-aware, e.g. the following does not work
    % \spy<2-> on (first) in node at (2,-2); 
    
    \onslide<3->
    \node at (0,-4) (third)  {Third text};


    \onslide<4->
    \node at (0,-6) (fourth)  {Fourth text};
    
    
  \end{tikzpicture}
  
\end{frame}

\end{document}

我的期望是间谍出现在第二张幻灯片上,但它总是只出现在最后一张幻灯片上。MWE 包括上述链接中的解决方法,但我没有看到任何行为差异,也无法重现这些解决方案。

有什么提示吗?

答案1

我不会在 tikzpicture 中使用\pause\onslide,这可能会产生“有趣”的副作用,例如使脚线消失。

如果您避免\onslide在第 3 和第 4 个覆盖层上使用文本,则链接问题的解决方案可以正常工作:

\documentclass[tikz]{beamer}

\usepackage{tikz}
\usetikzlibrary{spy}


% following https://tex.stackexchange.com/questions/88251/tikz-spy-and-beamer-uncover and  https://tex.stackexchange.com/questions/438218/beamer-uncover-magnification-using-tikz-spy-library: 

\tikzset{
    connect on/.style={alt={#1{connect spies}{}}},
}

\usetikzlibrary{overlay-beamer-styles}



\begin{document}

\begin{frame}
  \frametitle{test}

  \begin{tikzpicture}[spy using outlines={magnification=4, size=2cm, connect spies}]
    \node (first) {Initial text};

    \spy[overlay,visible on=<2->] on (first) in node at (2,-2);
    
    \node[visible on=<3->] at (0,-4) (third)  {Third text};

    \node[visible on=<4->] at (0,-6) (fourth)  {Fourth text};
        
  \end{tikzpicture}
  
\end{frame}

\end{document}

在此处输入图片描述

相关内容