This is kind of a follow up question of Bug in TikZ? Line width on layers.
When using a {pgfonlayer}
two problem occure: a) inside of the background scope settings from e.g. every picture
are missing. b) for drawing commands after closing {pgfonlayer}
the settings that where active before {pgfonlayer}
are lost. While a) seems to be “by design”, I’m not sure about b).
The code below produces this image:
1) is made with
on baclground layer
and works as documented.
2) is wrong
3) is the fixed version of 2)
4) and 5) are wrong
6) is again the fixed version.
As you can see it requires two additional {scope}
s to get the desired result. While Christian suggested only one as solution in the above mentioned question. This doesn’t seem to work (anymore?).
So basically the question is which of these might be a bug and is worth reporting?
Code
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{%
backgrounds,%
}
\tikzset{
medium/.style={line width=2.5pt},
thin/.style={line width=0.5pt},
every picture/.append style={medium},
every scope/.style={medium},
every on background layer/.style={every picture},
}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{document}
1 \begin{tikzpicture}
\draw (0,0) -- (1,1);
\begin{scope}[on background layer]
\draw [red] (0,1) -- (1,0);
\end{scope}
\draw (0,0) -- (1,0.5);
\end{tikzpicture}
\quad
2 \begin{tikzpicture}
\draw (0,0) -- (1,1);
\begin{pgfonlayer}{background}
\draw [red] (0,1) -- (1,0);
\end{pgfonlayer}
\draw (0,0) -- (1,0.5);
\end{tikzpicture}
\quad
3 \begin{tikzpicture}
\draw (0,0) -- (1,1);
\begin{scope}
\begin{pgfonlayer}{background}
\begin{scope}
\draw [red] (0,1) -- (1,0);
\end{scope}
\end{pgfonlayer}
\end{scope}
\draw (0,0) -- (1,0.5);
\end{tikzpicture}
\quad
4 \begin{tikzpicture}
\draw (0,0) -- (1,1);
\begin{pgfonlayer}{foreground}
\draw [red] (0,1) -- (1,0);
\end{pgfonlayer}
\draw (0,0) -- (1,0.5);
\end{tikzpicture}
\quad
5 \begin{tikzpicture}
\draw (0,0) -- (1,1);
\begin{pgfonlayer}{foreground}
\begin{scope}
\draw [red] (0,1) -- (1,0);
\end{scope}
\end{pgfonlayer}
\draw (0,0) -- (1,0.5);
\end{tikzpicture}
\quad
6 \begin{tikzpicture}
\draw (0,0) -- (1,1);
\begin{scope}
\begin{pgfonlayer}{foreground}
\begin{scope}
\draw [red] (0,1) -- (1,0);
\end{scope}
\end{pgfonlayer}
\end{scope}
\draw (0,0) -- (1,0.5);
\end{tikzpicture}
\end{document}