2

I would like to do Gantt chart in Latex thus I'm studying http://ftp.math.purdue.edu/mirrors/ctan.org/graphics/pgf/contrib/pgfgantt/pgfgantt.pdf, where I see

enter image description here

Is it possible to have the task names on the right side? Like this:

enter image description here

And to have names aligned to the left side will be nice.

Here is the code to generate the first chart:

\documentclass{article}

\usepackage{pgfgantt}

\begin{document}

\begin{ganttchart}{1}{12}

    \gantttitle{2011}{12} \\
    \gantttitlelist{1,...,12}{1} \\

    \ganttgroup{Group 1}{1}{7} \\
    \ganttbar{Task 1}{1}{2} \\
    \ganttlinkedbar{Task 2}{3}{7} \ganttnewline
    \ganttmilestone{Milestone}{7} \ganttnewline
    \ganttbar{Final Task}{8}{12}
    \ganttlink{elem2}{elem3}
    \ganttlink{elem3}{elem4}

\end{ganttchart}

\end{document}

If I do \begin{ganttchart}[group label node/.append style={anchor=west}]{1}{12} then I get (but I want that text all the way on the right side):

enter image description here

6
  • 1
    Please add a MWE taken from your linked source.
    – sztruks
    Commented Jan 24, 2019 at 8:21
  • 1
    MWE from the linked pgfgantt doc is there, anything else I can provide?
    – KcFnMi
    Commented Jan 24, 2019 at 9:00
  • This should be enough. I won't be able to help you, but now that the MWE is provided, you should see an answer quite soon.
    – sztruks
    Commented Jan 24, 2019 at 9:02
  • Already helped!
    – KcFnMi
    Commented Jan 24, 2019 at 9:05
  • 1
    I tried something, see there, not exacly what I want.
    – KcFnMi
    Commented Jan 24, 2019 at 9:21

1 Answer 1

2

You are on the right track with setting the anchor to west. Additionally, the horizontal (x axis) position of the node needs to be shifted from 0 to [width of the chart]. For this you need to change the code of pgfgantt.sty, which you can do on the fly with the xpatch package.

Borrowing code from the \ganttnewline command (around line 400) the width of the chart is defined as \gtt@chartwidth * \ganttvalueof{x unit}. The label nodes are drawn (around line 960) using the coordinates (0, \y@mid pt). When this line is patched, the position of the labels change.

Note that pgfgantt defines different styles for bar labels, group labels and milestone labels, so all three need to be defined explicitly (I could not find a single setting for all line labels).

MWE:

\documentclass{article}

\usepackage{pgfgantt}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\gtt@chartelement}{\node at (0, \y@mid pt)}{\node at (\gtt@chartwidth * \ganttvalueof{x unit}, \y@mid pt)}{}{}
\makeatother

\begin{document}

\begin{ganttchart}[bar label node/.append style={anchor=west},group label node/.append style={anchor=west},milestone label node/.append style={anchor=west}]{1}{12}

    \gantttitle{2011}{12} \\
    \gantttitlelist{1,...,12}{1} \\

    \ganttgroup{Group 1}{1}{7} \\
    \ganttbar{Task 1}{1}{2} \\
    \ganttlinkedbar{Task 2}{3}{7} \ganttnewline
    \ganttmilestone{Milestone}{7} \ganttnewline
    \ganttbar{Final Task}{8}{12}
    \ganttlink{elem2}{elem3}
    \ganttlink{elem3}{elem4}

\end{ganttchart}

\end{document}

Result:

enter image description here

2
  • Would be nice to have an option on pgfgantt to do this in one shot.
    – KcFnMi
    Commented Jan 24, 2019 at 10:41
  • @KcFnMi you could try to send a feature request to the package maintainer Wolfgang Skala, his e-mail address is listed in the pgfgantt manual.
    – Marijn
    Commented Jan 24, 2019 at 12:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .