是否可以在路径命令中定义要绘制的 tikz 层,例如\node[on main layer] at (0,0) {foo};
?将单个宏放在范围环境中有点繁琐。
答案1
选项behind path
并in front of path
允许叠加在同一个命令上绘制的节点和线。
\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}