[Tex/LaTex] pgfgantt: Moving a progress label to the left of a bar

pgfgantt

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

Best Answer

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}