6

I want to draw on a tikz-spy and the new line should be covering the ones copied by the spy. E.g.:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{spy,shapes}

\pgfdeclarelayer{bg}    % declare background layer
\pgfsetlayers{bg,main}  % set the order of the layers (main is the standard layer)


\begin{document}
\begin{tikzpicture}[spy using outlines={rectangle, width=4.5cm, height=3cm, magnification=4, connect spies,every spy on node/.append style={thin}},hide/.style={opacity=1}]

\begin{scope}
    \draw  circle (8) node[yshift=8.8cm,align=center] {};
    \draw  circle (8.2) node {};
    \draw (-5,7.4) -- (5,7.4);
\end{scope}

%\begin{pgfonlayer}{bg}    % select the background layer
\spy [black] on (-3.4,7.4) in node (spyleft) [left] at (-0.5,4.5);
%\end{pgfonlayer}

%\begin{pgfonlayer}{main}    % select the main layer
\draw[line width=2pt,color=blue] (-3.3,4.5) -- (-1.35,4.5) -- (-1.35,5.35) -- cycle;
%\end{pgfonlayer}

\end{tikzpicture}

\end{document}

should have the blue triangle on top of the black lines. Explicitly putting the parts of the drawing in a layer doesn't seem to help. Is there a specific spy-layer that I could address?

(Ideally I'd also like the corners of the triangle to be defined by the intersections of circles and the line but for now I'm happy to position it by hand if only I could get the layers right...)

1 Answer 1

5

Declare a foreground layer and put the blue triangle on that layer.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{spy,shapes}

\pgfdeclarelayer{fg}    % declare foreground layer
\pgfsetlayers{main,fg}  % set the order of the layers (main is the standard layer)


\begin{document}
\begin{tikzpicture}[spy using outlines={rectangle, width=4.5cm, height=3cm, magnification=4, connect spies,every spy on node/.append style={thin}},hide/.style={opacity=1}]

  \begin{scope}
      \draw  circle (8) node[yshift=8.8cm,align=center] {};
      \draw  circle (8.2) node {};
      \draw (-5,7.4) -- (5,7.4);
  \end{scope}
  
  \spy [black] on (-3.4,7.4) in node (spyleft) [left] at (-0.5,4.5);
  
  \begin{pgfonlayer}{fg}    % select the main layer
    \draw[line width=2pt,blue] (-3.3,4.5) -- (-1.35,4.5) -- (-1.35,5.35) -- cycle;
  \end{pgfonlayer}
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

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