I found a curios behavior in TikZ. If I set the line width globaly or for the current scope it wont affect the line with inside a {pgfonlayer}
but the arrow tips are changed:
Did I found a bug and does anyone know a solution or at least a workaround?
Code
\documentclass{minimal}
\usepackage{tikz}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{document}
\begin{tikzpicture}[line width=5pt]
\draw (0,0) -- (5,0);
\draw [<->] (0,1) -- (5,1);
\begin{pgfonlayer}{background}
\draw (0,2) -- (5,2) node [right] {on BG};
\draw [<->] (0,3) -- (5,3) node [right] {on BG};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
Update
As Christian Feuersäger said, it could be a feature that a new layer sets a fully new picture with the default settings. But in this case all settings should be reset. And in my opinion the every picture
style should be evaluated anyway.
Here’s an extended example showing the inconsequent behavior with every picture
(color is taken only for nodes of background layer, line width is completely ignored and arrow tips are changed even according to the line width
setting).
It shows also my workaround, since I’m using a shortcut for the {pgfonlayer}
environment it was easy to add a scope which uses every picture
. Unfortunately this {scope}
doesn’t respect settings given directly to the {tikzpicture}
. And it seems to be incompatible with Caramdir’s \makeatletter\tikz@options\makeatother
workaround …
\documentclass{minimal}
\usepackage{tikz}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\tikzset{every picture/.style={line width=5pt,blue,>=stealth}}
\newcommand{\bglayer}[1]{%
\begin{pgfonlayer}{background}
\begin{scope}[every picture]
#1
\end{scope}
\end{pgfonlayer}
}
\begin{document}
\begin{tikzpicture}[green]
\draw (0,0) -- (5,0);
\draw [<->] (0,1) -- (5,1);
\bglayer{%
\draw (0,2) -- (5,2) node [right] {on BG};
\draw [<->] (0,3) -- (5,3) node [right] {on BG};
}
\end{tikzpicture}
\end{document}
Follow up question: Restore TikZ settings after {pgfonlayer}