6

I'm using the pgfgantt package to draw a gantt chart and I am using different fill patterns for different task types (fill patterns for the task bars, that is). It works nicely! But I would like to add a legend to tell the reader which pattern stands for which kind of task.

I do believe that this is not possible from inside pgfgantt, but perhaps there are other ways of adding it?

1

1 Answer 1

7

I think I don't understand the question but you can add what you want inside the gantt environment. Here I added a node but you need to use current bounding box to place an object around or inside the tikzpicture.

enter image description here

\documentclass{article}
\usepackage{pgfgantt}

\begin{document}

\begin{figure}[ftbp]
\begin{center}

\begin{ganttchart}[y unit title=0.4cm,
y unit chart=0.5cm,
vgrid,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}]{24}
%labels
\gantttitle{Week}{24} \\
\gantttitle{Monday}{4} 
\gantttitle{Tuesday}{4} 
\gantttitle{Wednesday}{4} 
\gantttitle{Thursday}{4} 
\gantttitle{Friday}{4} 
\gantttitle{Saturday}{4} \\
%tasks
\ganttbar{first task}{1}{2} \\
\ganttbar{task 2}{3}{8} \\
\ganttbar{task 3}{9}{10} \\
\ganttbar{task 4}{11}{15} \\
\ganttbar[progress=33]{task 5}{20}{22} \\
\ganttbar{task 6}{18}{19} \\
\ganttbar{task 7}{16}{18} \\
\ganttbar[progress=0]{task 8}{21}{24}

%relations 
\ganttlink{elem0}{elem1} 
\ganttlink{elem0}{elem3} 
\ganttlink{elem1}{elem2} 
\ganttlink{elem3}{elem4} 
\ganttlink{elem1}{elem5} 
\ganttlink{elem3}{elem5} 
\ganttlink{elem2}{elem6} 
\ganttlink{elem3}{elem6} 
\ganttlink{elem5}{elem7} 
\node[fill=white,draw] at ([yshift=-12pt]current bounding box.south){Box South};
\node[fill=white,draw,anchor=west] at (current bounding box.north east){Box North East}; 
\end{ganttchart}
\end{center}
\caption{Gantt Chart}
\end{figure}

\end{document}
4
  • EI am currently without a PC, just my phone and vy slow internet, so I can't try this out this week. But it looks good. What I already learned from this is that the gantt chart can be embedded in a `\figure´ environment. I would then assume it could also be in ao tikzpicture? And then there might even be a legend package or so. I remember seeing s'th like that. In any case, I would like the legend to be inside the box of the chart, e.g. top left, above the labels.
    – Christoph
    Commented Jul 30, 2012 at 11:12
  • I get errors when I try to compile this. Has the package changed?
    – cfr
    Commented Apr 16, 2016 at 21:22
  • I guess the syntax has changed. You need another argument for the environment and group peaks needs to be split out, it seems. ?
    – cfr
    Commented Apr 16, 2016 at 21:39
  • @cfr Indeed. Here is the fix: tex.stackexchange.com/questions/587422/…
    – luchonacho
    Commented Apr 13, 2021 at 3:21

You must log in to answer this question.

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