4

In my Gantt chart (I'm using package pgfgantt), I have just one task in each line, one bar per task. Each bar has its corresponding label identifying the task aligned left of the chart; e.g.,

\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfgantt}

\begin{document}
\begin{ganttchart}[y unit title=0.4cm,
                    y unit chart=0.5cm,
                    vgrid={draw=none, dotted},
                    hgrid, 
                    title label anchor/.style={below=-1.6ex},
                    title left shift=.05,
                    title right shift=-.05,
                    title height=1,
                    bar/.style={fill=gray!50},
                    incomplete/.style={fill=white},
                    progress label text={},
                    bar height=0.7,
                    group right shift=0,
                    group top shift=.6,
                    group height=.3,
                    group peaks={}{}{.2}]{12}

    \gantttitle{2012}{12} \\
    \gantttitle{October}{4}
    \gantttitle{November}{4} 
    \gantttitle{December}{4}  

    \ganttgroup{Group 1}{1}{8}\\
    \ganttbar{Task 1}{1}{2} \\ 
    \ganttbar{Task 2}{3}{4} \\ 
    \ganttbar{Task 3}{5}{6}\\ 
    \ganttbar{Task 4}{1}{8} \\ 
\end{ganttchart}
\end{document}

Now, I would like to be able to add the resources assigned to each task by inserting an inline label right of each bar. I have had a look at /pgfgantt/bar label, which offers a number of configurations for adjusting labels associated with a bar, but I cannot find a way to use it for having two labels (offline and inline) in one label. Is there any way to do this using pgfgantt?

This picture shows the compiled code from above plus red labels indicating what is it that I want to achieve.

enter image description here

4
  • Welcome to the site, freieschaf. Please could you provide a compilable LaTeX document (starting with \documentclass and so on) that shows what you have got so far, and perhaps an annotated picture to clarify exactly what you want to achieve? Commented May 8, 2013 at 14:28
  • Thanks @JohnWickerson! I edited my question with your suggestions, hope it is easier to understand now. I did not attach the picture directly because I need higher reputation to do so.
    – freieschaf
    Commented May 8, 2013 at 14:46
  • There is progress label and various keys/styles to change its appearance. Commented May 8, 2013 at 14:59
  • I see now that you actually have emptied progress label text={} in the optional argument to the ganttchart environment … Commented May 8, 2013 at 15:22

1 Answer 1

3

Code (Update)

\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfgantt}

\makeatletter
\ganttset{
    prog default/.initial=100,
    prog/.code={
        \pgfutil@in@{:}{#1}
        \ifpgfutil@in@
            \pgfqkeysalso{/pgfgantt}{@prog={#1}}
        \else
            \pgfqkeysalso{/pgfgantt}{@prog={\pgfkeysvalueof{/pgfgantt/prog default}:#1}}
        \fi
    },
    @prog/.code args={#1:#2}{
        \pgfqkeysalso{/pgfgantt}{progress=100, progress label text={#2 (#1\,\%)}}
    }
}
\makeatother
\ganttset{progress label anchor/.append style={text=red}}
\begin{document}
\begin{ganttchart}[y unit title=0.4cm,
                    y unit chart=0.5cm,
                    vgrid={draw=none, dotted},
                    hgrid, 
                    title label anchor/.style={below=-1.6ex},
                    title left shift=.05,
                    title right shift=-.05,
                    title height=1,
                    bar/.style={fill=gray!50},
                    incomplete/.style={fill=white},
                    progress label text={},
                    bar height=0.7,
                    group right shift=0,
                    group top shift=.6,
                    group height=.3,
                    group peaks={}{}{.2},
                    ]{12}

    \gantttitle{2012}{12} \\
    \gantttitle{October}{4}
    \gantttitle{November}{4} 
    \gantttitle{December}{4} \\

    \ganttgroup{Group 1}{1}{8}\\
    \ganttbar[prog=50:  Resource 1]{Task 1}{1}{2} \\ 
    \ganttbar[prog=     Resource 2]{Task 2}{3}{4} \\ 
    \ganttbar[prog=     Resource 3]{Task 3}{5}{6}\\ 
    \ganttbar[prog=50:  Resource 1, progress label anchor/.append style={below=4pt}]{Task 4}{1}{8} \\ 
\end{ganttchart}
\end{document}

Output

enter image description here

Code

\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfgantt}

\makeatletter
\ganttset{
    prog default/.initial=100,
    prog/.code={
        \pgfutil@in@{:}{#1}
        \ifpgfutil@in@
            \pgfqkeysalso{/pgfgantt}{@prog={#1}}
        \else
            \pgfqkeysalso{/pgfgantt}{@prog={\pgfkeysvalueof{/pgfgantt/prog default}:#1}}
        \fi
    },
    @prog/.code args={#1:#2}{
        \edef\pgf@tempa{#1}%
        \ifx\pgf@tempa\tikz@nonetext
            \pgfqkeysalso{/pgfgantt}{progress={100},progress label text={#2}}
        \else
            \pgfqkeysalso{/pgfgantt}{progress={#1},progress label text={#2 (##1\,\%)}}
        \fi
    }
}
\makeatother
\ganttset{progress label anchor/.append style={text=red}}
\begin{document}
\begin{ganttchart}[y unit title=0.4cm,
                    y unit chart=0.5cm,
                    vgrid={draw=none, dotted},
                    hgrid, 
                    title label anchor/.style={below=-1.6ex},
                    title left shift=.05,
                    title right shift=-.05,
                    title height=1,
                    bar/.style={fill=gray!50},
                    incomplete/.style={fill=white},
                    progress label text={},
                    bar height=0.7,
                    group right shift=0,
                    group top shift=.6,
                    group height=.3,
                    group peaks={}{}{.2},
                    ]{12}

    \gantttitle{2012}{12} \\
    \gantttitle{October}{4}
    \gantttitle{November}{4} 
    \gantttitle{December}{4} \\

    \ganttgroup{Group 1}{1}{8}\\
    \ganttbar[prog=50:  Resource 1]{Task 1}{1}{2} \\ 
    \ganttbar[prog=     Resource 2]{Task 2}{3}{4} \\ 
    \ganttbar[prog=none:Resource 3]{Task 3}{5}{6}\\ 
    \ganttbar[prog=50:  Resource 1, progress label anchor/.append style={below=4pt}]{Task 4}{1}{8} \\ 
\end{ganttchart}
\end{document}

Output

enter image description here

2
  • Yes, that looks quite good, I will look at it carefully in a while. But actually, resources and their percentages don't have anything to do with the progress of a task: a resource works on the task, and its dedication (the percentage I added) means how much of their work effort goes into that task. I don't want to use progress on my chart so that's why it was empty in the gantchart options. Other than that, this could be a decent solution if I set progress=100 in every bar.
    – freieschaf
    Commented May 8, 2013 at 17:30
  • Well, yes, then just use progress label text=Resource 1 (50\,\%) for every bar. I have updated my answer. This way you do only have to specify Resource and (optional) the percentage. Commented May 8, 2013 at 17:48

You must log in to answer this question.

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