Is it possible to define a tikz style to access the background layer by adding a style option to the node instead of having to put the entire node inside the environment? Here is an example code:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}
\tikzset{
background/.style={%
execute at begin node={\begin{pgfonlayer}{bg}},
execute at end node={\end{pgfonlayer}}
}
}
\begin{tikzpicture}
\draw[thick,red] (-1,0) -- (1,0);
\begin{pgfonlayer}{bg}
\node[circle,fill=blue,label={blue node behind red line, good}] at (0,0){};
\end{pgfonlayer}
\draw[thick,red] (-1,-1) -- (1,-1);
\node[circle,fill=blue,background,label={blue node above red line, bad}] at (0,-1){};
\end{tikzpicture}
\end{document}
As you see in my example, I already tried to add a custom style but with no effect. Honestly, I do not really understand how to define new styles and this is more the result of copy-pasting, so it might be pointing in a totally wrong direction.
\draw
and\node[background]
command, not\draw ... node[behind path]