Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
The spy library will process the content multiple times. In this case this also includes the labels. –  Martin Scharrer Aug 12 '11 at 14:51
    
@Jake: I'll replace my code with yours and update my question accordingly.Thanks. –  SSilk Aug 12 '11 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 '11 at 15:13
    
Even \def\label#1{} before the \spy doesn't help. –  Caramdir Aug 12 '11 at 16:10
add comment

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
    
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 '11 at 2:56
    
@SSilk: It's already integrated =) –  Jake Aug 13 '11 at 3:12
    
Yay! Many Thanks! –  SSilk Aug 13 '11 at 14:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.