I am working at a quite complicated beamer presentation and at some point I could not manage to use the \spy command of TikZ as desired.
Trying to reproduce the problem, I came up with the following one-frame example (copying an example of the spy library from section 68.1 of the PGF manual):
\documentclass{beamer}
\usepackage{etex}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{backgrounds, decorations.fractals, spy}
\begin{document}
\begin{frame}[plain]
\begin{tikzpicture}[spy using overlays={size=12mm}]
\draw [decoration=Koch snowflake] decorate { decorate{ decorate{ decorate{ (0,0) -- (2,0) }}}};
\spy [green,magnification=3] on (0.6,0.1) in node at (-0.3,-1);
\spy [blue,magnification=5] on (1,0.5) in node at (1,-1);
\spy [red,magnification=10] on (1.6,0.1) in node at (2.3,-1);
\end{tikzpicture}
\end{frame}
\end{document}
Compiled as such, the magnified regions do not show anything but the coloured background.
Playing around with this code, I noticed that any of the following modifications solves the problem:
- Put the
\usepackage{pgfplots}line after the\usetikzlibraryone; - Comment out the
\usepackage{etex}line; - Do not load the
backgroundslibrary; - Load the
backgroundslibrary as last one.
Clearly, the last possibility is well suited for my problem (and I already adopted it for my presentation), but I would like to get a better understanding of what is going on in the code above.
- Which role do the packages
etexandpgfplotsplay in the game? - Why, in presence of such a packages, loading the
backgroundslibrary before thespyone causes the magnified regions to disappear? - More in general, why do the order of
TikZlibraries in the\usetikzlibrarycan matter? I would naively guess that it should not be the case.
Searching around before posting the question, I discovered in this answer a bit about how layers work, but this did not answer exactly my questions.
Clarification:
To produce the single frame in my example, the packages etex and pgfplots, as well as the backgrounds library, are not needed. However, I need them in my presentation.
\pgfkeysifdefined. Packages [tag:spy] and [tag:backgrounds] both defines the styleexecute at begin scopeand they may overwrite each other. – Symbol 1 Mar 27 '17 at 20:43