5

In an earlier question, I asked how to create zoomed highlights of a larger image automatically. User Jake provided an excellent solution using TikZ. However, when subcaptions and hyperref are added to the mix, we start getting multiply defined label warnings. Can anyone help diagnose the simplified example below?

When I compile this, I get the warning Label 'test' multiply defined.

Code example, courtesy of Jake:

\documentclass{article} 
\usepackage{tikz} 
\usetikzlibrary{spy} 

\begin{document} 

\begin{figure}\centering 
        \begin{tikzpicture}[spy using outlines] 
                \node{\label{test} Testcontent}; 
                \spy on (0,0) in node (0,0); 
        \end{tikzpicture} 
\caption{Testfigure} 
\end{figure} 

\end{document}
4
  • The spy library will process the content multiple times. In this case this also includes the labels. Aug 12, 2011 at 14:51
  • @Jake: I'll replace my code with yours and update my question accordingly.Thanks.
    – SSilk
    Aug 12, 2011 at 15:09
  • @Martin: Do you have any thoughts on how to place labels so they don't get processed repeatedly by spy? Thanks.
    – SSilk
    Aug 12, 2011 at 15:13
  • Even \def\label#1{} before the \spy doesn't help.
    – Caramdir
    Aug 12, 2011 at 16:10

1 Answer 1

4

As Martin pointed out, using spy means the picture gets processed several times, which means the label also gets defined several times.

One way to get around this is to keep the spy inside a scope, and place the nodes with the labels after this scope, e.g. using the fit library to place the "label" node on top of the original one.

\documentclass{article} 
\usepackage{tikz} 
\usetikzlibrary{spy,fit} 

\begin{document} 

\begin{figure}\centering 
\begin{tikzpicture}
    \begin{scope}[spy using outlines] 
        \node (testnode) {Testcontent}; 
        \spy[size=1cm,magnification=2] on (0,0) in node at (1.5,1); 
    \end{scope}
    \node [fit=(testnode),inner sep=0pt] {\label{test}};
\end{tikzpicture} 
\caption{Testfigure} 
\end{figure} 

\end{document}
2
  • This looks good on my end. Would it be difficult to integrate this approach into your zoombox code from my previous question? If you don't have time, I'll try to do it in the next few days. Thanks.
    – SSilk
    Aug 13, 2011 at 2:56
  • 2
    @SSilk: It's already integrated =)
    – Jake
    Aug 13, 2011 at 3:12

You must log in to answer this question.

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