I have used pgfgantt
to produce a simple Gantt chart for the work packages of my project:
\documentclass{article}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[expand chart=\textwidth]{1}{48}
\gantttitle[]{Year 1}{12}
\gantttitle[]{Year 2}{12}
\gantttitle[]{Year 3}{12}
\gantttitle[]{Year 4}{12}\\
\ganttbar{WP1}{1}{48} \\
\ganttbar{WP2}{4}{15} \\
\ganttbar{WP3}{10}{30} \\
\ganttbar{WP4}{20}{45}
\end{ganttchart}%
\end{document}
I want to colour-code the bars according to which staff members will be assigned to each work package. There are six staff members in total, each with a unique colour. Up to three staff members will work on each work package. Ideally I'd like to show this with diagonal stripes, since horizontal stripes might be too thin to make out, and vertical stripes would be confused with allocation to the time subdivisions. Basically I'd like to be able to colour the bars like this, with one, two, or three colours per bar:
I have found a few examples here of two-colour stripes, but they don't seem to be easily adaptable to three-colour stripes.
Best Answer
Tikz (or pgf) patterns can solve your problem.
To fill with n-color stripes (n >= 2) using an uncolored pattern (also called "form-only"), you have to apply a pattern n-1 times since an uncolored pattern can only have a single color, which is specified by option
pattern color
.Notice how the linked answer uses normal filling and an uncolored pattern in
postaction
to achieve a two-color stripes. So a three-color stripes will need twopostaction
.To do the same task using a colored pattern, a new pattern
Stripes
is defined in the example below. It is similar to the patternLines
from tikz librarypatterns.meta
, with a new optioncolor series={<comma list of colors>}
. Theline width
option is invalid and now auto computed as 1/n ofdistance
in which n is the length ofcolor series
. Hence withdistance=6pt, color series={red, blue}
, the line width is 3pt; withdistance=6pt, color series={red, green, blue}
, the line width is 2pt.color series
has initial and default valuered, green, blue