3

I'm putting together a Gantt chart with pgfgantt. I would like to use progress labels to annotate resources to tasks (using the standard bar label on the left of the chart as usual). This works well, but for the final tasks of my chart the labels extend well beyond the right edge of the chart and, indeed, beyond the margins of my page. I could, of course, try to make my chart smaller, but that would make it unreadable. So, instead, I am hoping to move the progress label to the left of the bar for these bars.

Having read the relevant parts of the pgfgantt documentation and a number of on-line articles, I have come up with the following code (only showing the relevant ganttbar command):

\ganttbar[progress label text={Resource 7},
          bar progress label anchor=west]%
         {Task Label}{12}{15}

This moves the start of the progress label nicely to the left of the bar, but the text of the label now overlaps with the bar. Instead, I would like to move the text fully to the left of the bar. I have then tried various variations of the below, but I'm clearly misunderstanding something here as none of these changes make any difference whatsoever:

\ganttbar[progress label text={Resource 7},
          bar progress label node /.append style={anchor=east,left=.5cm},
          bar progress label anchor=west]%
         {Task Label}{12}{15}

The documentation isn't particularly helpful here and I do not know enough of PGF/TikZ to figure this out from source.

Any suggestions?

EDIT

Here's an MWE to make my problem more explicit:

\documentclass{article}

\usepackage[utf8]{inputenc}

\usepackage{pdflscape}
\usepackage{pgfgantt}

\begin{document}
    \begin{landscape}
        \begin{ganttchart}%
                    [hgrid,
                     vgrid={draw=none, draw=none, dotted},
                     progress=100,
                     progress label text={}]%
                    {1}{36}
            \gantttitle{Y1}{12} \gantttitle{Y2}{12} \gantttitle{Y3}{12} \\
            \gantttitlelist{1,...,36}{1} \\
            \ganttbar[progress label text={Resource1}]{Task1}{32}{36} \\
            \ganttbar[progress label text={Resource2},
                      bar progress label anchor=west]{Task2}{32}{36} \\
            \ganttbar[progress label text={Resource3},
                      bar progress label node /.append style={anchor=east,left=.5cm},
                      bar progress label anchor=west]{Task3}{32}{36}
        \end{ganttchart}
    \end{landscape}
\end{document}

This produces the following chart:

Simple gantt chart with resource annotations

Task1 shows what happens with normal progress annotations. In my original document, these annotations go beyond the page margin. Tasks 2 and 3 show my unsuccessful attempts at moving that label to the left of the bar.

The image below shows a mock up of what I would like to achieve (ignore the fact that the label partially hides the grid line; that's an accidental effect of how I created the mock up).

Simple gantt chart with resource annotations to the left of bar

4
  • Welcome. Could you add a minimal working example (MWE)?
    – Bobyandbob
    Jul 14, 2017 at 18:23
  • Thanks @Bobyandbob. I have edited my question to add an MWE. Jul 20, 2017 at 6:39
  • Maybe rather than using progress label text, use the inline label instead and move it around like here: tex.stackexchange.com/a/199854
    – Ross
    Jul 20, 2017 at 7:03
  • Thanks, @Ross . The reason I was using progress labels was that inline labels remove the label on the left of the Gantt chart. The question you reference (and which I had previously looked at) works around this by duplicating the bar, which seems a bit heavy weight. Whether I use inline or progress labels, my main challenge is how to move the label to the right position. I have tried using /.style={left... in various variations, but this doesn't seem to do anything at all. Jul 20, 2017 at 7:28

1 Answer 1

3

This answer sets up two new Gantt chart elements using the \newganttchartelement* macro. It takes a single optional argument and two mandatory arguments <label> and the time slot, <tss>. It operates the same way as does the \milestone macro. The newgantchartelement named lresource can be used to set a node on the left of the task to define the corresponding resource. tss can be given by a value >=1 less than the tss for the corresponding task. For left placed resources, the resource must be specified before the task. The same logic applies to rresource newganttchartelement, except that it sets the resource on the right of the corresponding task. In this case, the resource must be specified after the task.

Regarding the OP's question about setting [inline=false] globally for ganttbar, this may not be possible. The manual says in section 2.2:

Since pgfgantt uses the pgfkeys package for key management, all its keys reside in the /pgfgantt/ path.

My interpretation of this statement is that having set inline=true for the lresource and rresource, that setting operates globally until it is specifically reset in each ganttbar by writing ganttbar[inline=false].

This is the result, with the ganttbar[inline=false]:

enter image description here

Here is the MWE, with some additional comments in the code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pdflscape}
\usepackage{pgfgantt}
\pagestyle{empty}

\newganttchartelement*{lresource}{ % The starred version mimics a milestone element with 2 options
    lresource/.style={}, % Don't draw the node
    inline=true,
    lresource inline label node/.style={anchor=east,font=\bfseries\itshape\color{blue}},
    lresource left shift=0ex,
    lresource right shift=0ex
}
\newganttchartelement*{rresource}{
    rresource/.style={},
    inline=true,
    rresource inline label node/.style={anchor=west,font=\bfseries\itshape\color{blue}},
    rresource left shift=0ex,
    rresource right shift=0ex
}

\begin{document}
\begin{landscape}
\begin{ganttchart}[
    hgrid,
    vgrid={draw=none, draw=none, dotted},
    progress=100,
    progress label text={}]%
    {1}{36}
    \gantttitle{Y1}{12} \gantttitle{Y2}{12} \gantttitle{Y3}{12} \\
    \gantttitlelist{1,...,36}{1} \\
    \ganttlresource{resource}{5} % Make the tss value one less than the start of Task 1
    \ganttbar[inline=false]{Task1}{6}{10} \\
    \ganttlresource{resource}{31} % Make the tss value one less than the start of Task 2
    \ganttbar[inline=false]{Task2}{32}{36} \\
    \ganttbar[inline=false]{Task3}{15}{19}
    \ganttrresource{resource}{20} % Make the tss value one more than the end of Task 3
\end{ganttchart}
\end{landscape}
\end{document}
4
  • Thanks, this is very nice. Unfortunately, it makes the actual task labels inline as well. I was able to fix this by adding explicit [inline=false] to each \ganttbar call. Can you think of a way where I don't have to add this every time? Jul 20, 2017 at 14:45
  • This also doesn't work too well with \ganttlinkedbar and friends, but that can be easily fixed by making explicit links. Jul 20, 2017 at 15:20
  • @Steffen Thanks for pointing out the incorrect placement of the bar labels. I updated the answer accordingly. Regarding whether [inline=false] can be set globally, this may not be possible (see above), and indeed nothing I have tried worked.
    – Ross
    Jul 20, 2017 at 16:00
  • Thanks for the update. I had tried [inline=false] as a parameter of the Gantt chart environment and can confirm that this breaks the resource annotation commands. Your solution is the only one so far that seems to work. Jul 21, 2017 at 4:35

You must log in to answer this question.

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