# pgfgantt: draw arrows (links) behind bars

I want to draw a Gantt diagram using pgfgantt. With the default settings, it draws the bars first and the arrows/links second. Thereby, the bars are crossed by the arrows which I find utterly ugly. Is it possible to change this behaviour, e.g., to define the z-order of drawing ?

Minimal working example:

\documentclass{article}
\usepackage{pgfgantt}

\begin{document}
\begin{tikzpicture}
\end{ganttchart}
\end{tikzpicture}
\end{document}


The example works with pgfgantt.sty version 4.0.

-
You can with the backgrounds library and the option on background layer or simply with PGF layers (without a library available). Problem is though that the whole chart is filled in white. You will need more than two layer (background and main) or disable that filling somehow. –  Qrrbrbirlbel Aug 26 '13 at 13:19
Thanks for pointing on PGF layers. My issue appears to be related to this question. –  Erwin411 Aug 26 '13 at 13:37
If it draws under the tasks the meaning of the link changes (Task1 is involved in Task2 to be able to finish and both lead to Task 3) so it is actually a good thing. –  percusse Aug 26 '13 at 13:53

Setting the canvas to fill=none, one can simply use the backgrounds library and the on background layer key to draw the arrow behind “Task 2”. I also set the outer xsep to zero so that the f-s line is perfectly straight.

To avoid ambiguity about that arrow corssing under “Task 2” I would draw the arrow around as in Example Y below. (One could also think of keys that only add to already established link bulge value.)

## Code X

\documentclass[tikz,convert=false]{standalone}
\usepackage{pgfgantt}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{ganttchart}[
/pgf/outer xsep=+0pt,
bar/.append style={orange},
canvas/.append style={fill=none},
\begin{scope}[on background layer]
\end{scope}
\end{ganttchart}
\end{document}


## Code Y

\documentclass[tikz,convert]{standalone}
\usepackage{pgfgantt}
(\xLeft, \yUpper) --
(\xLeft + \ganttvalueof{link bulge 1} * \ganttvalueof{x unit},
\yUpper) --
($(\xLeft + \ganttvalueof{link bulge 1} * \ganttvalueof{x unit}, \yUpper)!% \ganttvalueof{link mid}!% (\xLeft + \ganttvalueof{link bulge 1} * \ganttvalueof{x unit}, \yLower)$) --
($(\xRight - \ganttvalueof{link bulge 2} * \ganttvalueof{x unit}, \yUpper)!% \ganttvalueof{link mid}!% (\xRight - \ganttvalueof{link bulge 2} * \ganttvalueof{x unit}, \yLower)$) --
(\xRight - \ganttvalueof{link bulge 2} * \ganttvalueof{x unit},
\yLower) --
(\xRight, \yLower);%
}
\ganttset{
\begin{document}
\begin{ganttchart}[
bar/.append style={orange},
\end{ganttchart}
\begin{ganttchart}[
bar/.append style={orange},
\end{ganttchart}
\end{document}


## Output Y

-
very nice but unfortunately horizontal axis is often time so that's time travel ;) –  percusse Aug 26 '13 at 22:30
Thanks a lot for the short solution "X" ... and for the beautiful version "Y". –  Erwin411 Aug 27 '13 at 7:18