[Tex/LaTex] Draw TikZ arrow heads in the foreground

tikz-arrowstikz-pgf

I have a figure with open (white) arrow heads. Paths that I draw might overlap with arrow heads that were drawn earlier by TikZ and therefore are placed in the foreground. I do not like how this looks and I would like all arrow heads to be placed on the foreground so that no paths are placed on top of the arrow heads.

This description is vague, but with the MWE it hopefully makes sense.

MWE

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usetikzlibrary{arrows.meta}

\tikzset{%
    state/.style = {%
        draw, circle, minimum size = 4, inner sep = 0, fill = black
    }%
}% 

\tikzset{%
    dashedarrow/.style = {%
        draw, densely dashed, > = {Latex[width = 1.7mm, length = 2.2mm, open, fill = white]}, ->
    }%
}% 

\begin{document}%
\begin{tikzpicture}%

\node[state] (0) at (0,0) {};
\node[state] (1) at (1,0) {};
\node[state] (2) at (0,1) {};

\path[dashedarrow] (1) edge[bend left = 20] (2);
\path[dashedarrow] (2) edge[bend left = 20] (0);

\end{tikzpicture}%
\end{document}%

The MWE produces

Result of the MWE

By simply changing the order of the two \path[dashedarrow] ... lines I get the result that I want:

Required result

However, there is no guarantee that this solution works when I increase the number of arrows: there might not exist an order for which each arrow head is in the foreground.

Is there a way in which I can force all arrow heads to be drawn on the foreground such that nothing will be drawn over them? You can assume that the arrow heads are not drawn so close to each other that they might touch or overlap.

Best Answer

Using the markings library you can instruct tikz to draw the arrows on a top layer. This requires changing the edge notation to to (as edge doesn't seem to add to the path so that the marking can be applied).

\documentclass{standalone}

\usepackage{tikz}
\pgfplotsset{compat = newest}
\usetikzlibrary{arrows.meta, decorations.markings}
\pgfdeclarelayer{arrowlayer}
\pgfsetlayers{main,arrowlayer}
\tikzset{%
    state/.style = {%
        draw, circle, minimum size = 4, inner sep = 0, fill = black
    }%
}%

\tikzset{%
    dashedarrow/.style = {%
        draw, densely dashed, > = {Latex[width = 1.7mm, length = 2.2mm, open, fill = white]},
        decoration={markings, mark=at position 1 with {\begin{pgfonlayer}{arrowlayer}\arrow{>}\end{pgfonlayer}}},
        postaction={decorate}
    }%
}%


\begin{document}%
\begin{tikzpicture}%

\node[state] (0) at (0,0) {};
\node[state] (1) at (1,0) {};
\node[state] (2) at (0,1) {};

\path[dashedarrow] (1) to[bend left = 20] (2);
\path[dashedarrow] (2) to[bend left = 20] (0);

\end{tikzpicture}%
\end{document}%

arrows on top layer