2

TikZ spy and Beamer \pause, \onslide, ... do not seem to work well together. This has been observed in several previous, albeit older questions (in particular, 1 and 2 ), but the workarounds shown there do not work for me.

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}

My expectation is to have the spy show up on the second slide, but it always only shows up on the last slide. MWE comprises the workarounds from the links above, but I do not see any difference in behaviour and cannot reproduce these solutions.

Any hints?

1 Answer 1

1

I would not use \pause or \onslide in a tikzpicture, this can have "funny" side effects like making footlines disappear.

The solutions from your linked questions work fine if you refrain from using \onslide for the text on your 3rd and 4th overlays:

\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}

enter image description here

2
  • I did not expect the on slides AFTER the spy environment to still be a problem, but makes sense, of course. So, thanks a lot! Apr 12, 2023 at 11:07
  • @HolgerKarl You're welcome! Apr 12, 2023 at 11:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .