7

I have a pretty complex pgfgantt chart. Several people are collaboratively working on it and it is subject to frequent change.

In this chart the individual \ganttbar items are linked with the \ganttlink command. The ganttbar items are referred to by elem0, elem1, ..., elemn.

To illustrate my problem consider this minimal pgfgantt example:

\begin{ganttchart}{3}{1}
\ganttbar {Task 1}{1}{2} \\
\ganttbar {Task 2}{2}{3} \\
\ganttbar {Task 3}{1}{2} \\
\ganttbar {Task 4}{2}{3}
\ganttlink {elem0}{elem1}
\ganttlink {elem2}{elem3}
\end{ganttchart}

Now lets assume that "Task 2" is removed:

\begin{ganttchart}{3}{1}
\ganttbar {Task 1}{1}{2} \\
\ganttbar {Task 3}{1}{2} \\
\ganttbar {Task 4}{2}{3}
\ganttlink {elem1}{elem2}
\end{ganttchart}

Of course I have to remove \ganttlink {elem0}{elem1}. However I also have to change all subsequent links as well in order to maintain the correct relationships. In the example above \ganttlink {elem2}{elem3} had to be changed to \ganttlink {elem1}{elem2}. In a complex gantt chart this quickly becomes tedious and very error prone .

So my question is: Is it possible to reference a \ganttbar rather by a custom name than by elemn, e.g. \ganttlink{mytask1}{mytask2}?

7

The option name to ganttbar allows you to change the name of the element to whatever you want. Use this as

\ganttbar[name=myname]{Title}{1}{3}

and thereafter refer to this element as myname.

Sample output

\documentclass{article}

\usepackage{pgfgantt}

\begin{document}
\begin{ganttchart}[x unit=2cm,vgrid]{1}{4}
\ganttbar[name=t1] {Task 1}{1}{2} \\
\ganttbar[name=t2] {Task 2}{2}{3} \\
\ganttbar[name=t3] {Task 3}{1}{2} \\
\ganttbar[name=t4] {Task 4}{2}{3}
\ganttlink {t1}{t2}
\ganttlink {t3}{t4}
\end{ganttchart}

\medbreak

\begin{ganttchart}[x unit=2cm,vgrid]{1}{4}
\ganttbar[name=t1] {Task 1}{1}{2} \\
%\ganttbar[name=t2] {Task 2}{2}{3} \\
\ganttbar[name=t3] {Task 3}{1}{2} \\
\ganttbar[name=t4] {Task 4}{2}{3}
%\ganttlink {t1}{t2}
\ganttlink {t3}{t4}
\end{ganttchart}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.