3

Is it possible to define the tikz-layer to draw on inside a path command, eg \node[on main layer] at (0,0) {foo};? It is a bit tedious to put single macros in a scope-environment.

Jürgen
  • 2,160
  • It doesn't save much but, of course, you could always define \newcommand\Scope[2][]{\begin{scope}[#1]#2\end{scope}} and then use constructs like \Scope{\node at (0,0){foo};} and \Scope[rotate=30]{\node at (0,0){foo};}. –  Feb 23 '18 at 07:28
  • Which path command do you usually use? That's just a single node – percusse Feb 23 '18 at 07:38
  • 1
    With scopes library you can use {[on background layer]\node {foo};}, i.e., {...} instead of \begin{scope}...\end{scope}. – Ignasi Feb 23 '18 at 07:38
  • @ Zarko: Is it simply not possible due to the internal structure or is it not implemented yet? – Jürgen Feb 23 '18 at 07:38
  • @ percusse: Different, but at this moment I am just interested in the \node command. – Jürgen Feb 23 '18 at 07:40
  • Recent tikz-layers package define some more layers: behind, above and glass. – Ignasi Feb 23 '18 at 07:40
  • @ Ignasi: Yes, but it works only (as far as I can see) on the scope-level, alas. – Jürgen Feb 23 '18 at 07:41
  • @ Ignasi: The scopes library seems to be interesting. I will have a look at it. Thanks! – Jürgen Feb 23 '18 at 07:43
  • 1
    https://tex.stackexchange.com/questions/20425/z-level-in-tikz?noredirect=1&lq=1 – Torbjørn T. Feb 23 '18 at 07:44
  • Ok, Torbjorn's hint seems to be the right way. It seems to be a complicated so I have to have a closer look. Thanks for the link! --- [four minutes later: works like a charm] – Jürgen Feb 23 '18 at 08:30

1 Answers1

5

Options behind path and in front of path allows to superpose nodes and lines that are drawn on the same command.

\documentclass[tikz,border=2mm]{standalone} 

\begin{document}
\begin{tikzpicture}

\draw[thick, draw=green] (0,0) -- 
     node[pos=0.25, behind path, fill=red!30 ]{A} 
     node[pos=0.75, fill=red!30 ]{A} (2,0);

\path (1,1) node[fill=blue!20] {A} 
            node[fill=green, behind path, inner sep=3mm] {A} 
            node[fill=red, inner sep=1mm, in front of path] {};
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588
  • That's fine and I'll keep it in mind for tasks to come, but I think this does not fit my original question. I need to put something on top of other paths, drawn later. – Jürgen Feb 23 '18 at 08:28