For a group of plots i want to place all x tick labels on the top layer so that lines, that have been drawn at the end of the tikzpicture environment, are on a layer below the labels.
I already tried to set the layer with on top layer
but unfortunately a scope
environment seems to be always needed to draw on a specific layer.
My example below illustrates the problem. The goal is that the x tick label node at x=2 is eventually placed on top of the dashed line.
Example
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz-layers}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{backgrounds}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture]
\begin{groupplot}[
no markers,
xmax=6,
ymin=0,
every x tick label/.style={
fill=red
},
group style = {
group size = 1 by 2,
},
]
\nextgroupplot[ymax=15]
\addplot +[domain=0:6] {0.5*x^2};
\coordinate (t1g1-top) at (axis cs:2,15);
\coordinate (t1g1-bottom) at (axis cs:2,0);
\nextgroupplot
\addplot +[domain=0:6] {x};
\coordinate (t1g2-bottom) at (axis cs:2,0);
\end{groupplot}
\begin{scope}[on above layer]
\draw[dashed, ultra thick] (t1g1-top) -- (t1g2-bottom);
\end{scope}
\end{tikzpicture}
\end{document}