2

When using the TikZ spy library in a tikzpicture it “forgets” the line properties, e.g. line join, set previously.

I have looked into the spy library code (at pgf/pgf/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryspy.code.tex) and noted these lines:

\tikzset{
  tikz@lib@reset@gs/.style={black,thin,solid,opaque,line cap=butt,line join=miter}
}

A first quick fix was to use

\tikzset{
    spy scope/.append style={
        line width=5pt,
        line join=round,
    },
}

which fixes it for all the image parts that are not magnified, but the lines in the magnified part are still drawn with properties reset.

Setting the property directly to the drawn path preserves it for both parts of the picture.

enter image description here

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

\tikzset{
    thick round path/.append style={
        line width=5pt,
        line join=round,
    },
    every picture/.append style={
        thick round path
    },
}

\begin{document}

\section{No \texttt{spy} library}
\begin{tikzpicture}
    \draw (0,.2) -- (1,0) -- (0,-.2);
\end{tikzpicture}

\section{\texttt{spy scope} set}
\begin{tikzpicture}[spy scope]
    \draw (0,.2) -- (1,0) -- (0,-.2);
\end{tikzpicture}

\tikzset{
    spy scope/.append style={
        thick round path
    },
}

\section{\texttt{spy scope} set but \texttt{spy scope/.append style} used}
\begin{tikzpicture}[spy scope]
    \draw (0,.2) -- (1,0) -- (0,-.2);
\end{tikzpicture}

\section{Actually magnifying}
\begin{tikzpicture}[spy using outlines={circle, size=1cm, magnification=2}]
    \draw (0,.2) -- (1,0) -- (0,-.2);
    \spy on (1,0) in node at (2,0);
\end{tikzpicture}

\section{Setting property directly on drawn line}
\begin{tikzpicture}[spy using outlines={circle, size=1cm, magnification=2}]
    \draw[thick round path] (0,.2) -- (1,0) -- (0,-.2);
    \spy on (1,0) in node at (2,0);
\end{tikzpicture}

\end{document}

I would like to prevent having to specify a property to every line I draw since that can be many. Is there a different way to achieve what I want?

  • 1
    Why not every path/.style={thick round path} – Salim Bou Jan 14 '17 at 15:35
  • Well that is embarrassing. I didn't know about every path. Totally works. Do you want to make an answer out of your comment? – Artemis Jan 16 '17 at 9:07
  • A small follow up: The every path solution prevents clip from working. The solution for this can be found here: tex.stackexchange.com/a/88222 – Artemis Jan 16 '17 at 9:27
1

The library defined the following

\tikzset{
  tikz@lib@reset@gs/.style={black,thin,solid,opaque,line cap=butt,line join=miter}
}

This will reset almost everything.

The logic behind this is that this library wants to control these variables so the image in the magnifying lens looks coherent. (For example, black lines are still black).

The cheapest way to control them is to reset them unless the user explicitly assigns something in the current scope. In that case the images will still be coherent because the assignment will be executed twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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