[Tex/LaTex] tikz spy with beamer overprint

beameroverlaystikz-pgf

In my presentation, I want to successively highlight different parts of my image using the TikZ spy library.
Due to size constraints, the actual highlight is outside of the included image.
Therefore, I use beamers overprint environment with onslide.
This works fine for \node, but I cannot get it to work for \spy.

Below is a minimal, not working, example. I described the problems in the comments.

\documentclass[12pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}
\begin{frame}
\begin{overprint}
\begin{tikzpicture}[spy using outlines={circle, blue, magnification=6, connect spies}]
% bluemarble from http://en.wikipedia.org/wiki/File:Apollo17WorldReversed.jpg
\node<1-> (image) at (0,0) {\includegraphics[width=6cm]{bluemarble}};
% this one compiles, but image jumps around
% \only<2->{\spy [size=3cm] on (1,1) in node at (4, 4);}
% this one fails to compile with: ! Extra }, or forgotten \endgroup.
% \onslide<2->\spy [size=3cm] on (1,1) in node at (4, 4);
% this one fails to compile with:
% Runaway argument?
% ]<2-> [size=3cm] on (1,1) in node at (4, 4); \end {tikzpicture} \end \ETC.
% ! Paragraph ended before \tikz@lib@spy@parse@opta was complete.
\spy<2-> [size=3cm] on (1,1) in node at (4, 4);
% these compile, but 'spy' is on every slide
% \onslide<2->{\spy [size=3cm] on (1,1) in node at (4, 4);}
% \uncover<2->{\spy [size=3cm] on (1,1) in node at (4, 4);}
\end{tikzpicture}
\end{overprint}
\end{frame}
\end{document}

The beamer user guide, section 6.3.1., Making Commands and Environments Overlay Specification-Aware, but I'm not sure how to apply this \renewcommand<> thing to \spy to make it overlay-specification aware, since \spy does not look like an "ordinary" command as I would create with (re)newcommand.

How can I use \spy without my image "jumping around", e.g. with a (preferably automatically calculated) bounding box remaining constant for the different slides?

Best Answer

You could try making the node an overlay: \only<2->{\spy [size=3cm] on (1,1) in node[overlay] at (4, 4);} Then you don't need the overprint environment at all. An overlay node means it is not added to the bounding box.