About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.


12.4 Gantt Charts

A Gantt chart (named after Henry Gantt) is a form of bar chart used to illustrate the work breakdown structure of a project. At the time of writing, the gantt topic has four entries, one of which is for ConTeXt. The remaining three are all LaTeX packages available on both MiKTeX and TeX Live. The pgfgantt package [88] uses tikz, and the pst-gantt [27] and rtsched [54] packages use pstricks.

This section discusses the pgfgantt package, since it's driver-independent and uses the pgfcalendar package, which has already been introduced in §7.2 The pgfcalendar Package Utility Commands. If you want to use the pgfgantt package, make sure you have an up-to-date version of the pgf package installed.

The pgfgantt package defines the ganttchart environment, which can be used to generate a Gantt chart.

\begin{ganttchart}[options]{start tss}{end tss}
entries
\end{ganttchart}

The optional argument ⟨options⟩ is a key=value list. You can also use these keys in the optional argument of the commands, described below, provided for use within the ganttchart environment to apply the setting to just that element. Alternatively you can use

\ganttset{options}

to apply the settings to the current scope.

For the mandatory ganttchart environment arguments, ⟨start tss⟩ is the starting time slot specifier and ⟨end tss⟩ is the end time slot specifier. The Gantt chart consists of several lines, which may contain title elements or chart elements. Each unit on the chart's x-axis represents a time slot.

Note that none of the elements start a new row. Instead you need to explicitly insert a line break using:

\ganttnewline[style]

where ⟨style⟩ is a key=value list of options permitted by tikz's \path optional argument (such as draw=red). The default starts a new row without drawing anything.

A time slot specifier (tss) represents a time slot along the horizontal axis. The format used to specify a time slot is determined by the value of the time slot format key (which may be set in ⟨options⟩). This key may take one of the following values:

simple
Each time slot is specified as a positive integer, where 1 indicates the value of the time slot format/start date key (see below), 2 indicates the day after time slot format/start date etc.

isodate
Each time slot is specified using the ISO-standard format yyyy⟩-⟨mm⟩-⟨dd. (The leading zero is optional for the month or day.)

isodate-yearmonth
As isodate but without the day -dd⟩ part. The date is assumed to be the first day of the month.

little-endian
Each time slot is specified in dd⟩-⟨mm⟩-⟨year format. (You may also use a slash (/) or period (.) instead of a hyphen (-) for the separator.) A two-digit year will be completed according to the base century setting.

middle-endian
As little-endian but with the ⟨dd⟩ and ⟨mm⟩ swapped.

big-endian
As little-endian but with the order reversed (⟨yyyy⟩ first and ⟨dd⟩ last).

Other keys that may be used with ⟨options⟩ include:

time slot format/base century
Sets the century for the auto-completion of two-digit years. The default is 2000.

time slot format/start date
An ISO-standard date yyyy⟩-⟨mm⟩-⟨dd denoting the value of the time slot 1 when using the simple format. The default is 2000-01-01, so the time slot 1 indicates 2000-01-01, the time slot 2 indicates 2000-01-02, etc.

canvas/.style
This sets the canvas style. The value should be an option list valid for the optional argument of a tikz node. (See §7.5 Displaying a Calendar and §12.1 Flow Charts.) The default is {shape=rectangle,draw,fill=white}, which creates a white canvas with a rectangular frame.

newline shortcut
This is a boolean key. If true this will allow you to use \\ as a shortcut for \ganttnewline.

compress calendar
This is a boolean key. If true, one month corresponds to one time slot, otherwise one day corresponds to one time slot.

There are many other options that govern the chart's formatting, see the pgfgantt manual [88] for further details.

Within the ganttchart environment, you can use the commands described below to create chart elements. In each case, ⟨options⟩ is as for the ganttchart environment.

\gantttitle[options]{text}{n}

Draws a single title element that covers ⟨n⟩ time slots, with the given ⟨text⟩.

\gantttitlelist[options]{list}{n}

This iterates over ⟨list⟩ and draws a title element that spans ⟨n⟩ time slots for each item in the list. The title text is given by the current list element. The list should be in the format accepted by \foreach (see §2.7.2 Iterating Over a Comma-Separated List).

\gantttitlecalendar[options]{calendar lines}

This prints a title calendar that spans the whole chart. The starred form

\gantttitlecalendar*[options]{start tss}{end tss}{calendar lines}

spans from ⟨start tss⟩ to ⟨end tss⟩. In both cases, ⟨calendar lines⟩ is a comma-separated list of line types:

year
Print the year.

month
Print the month number. This may optionally be followed by =format⟩ where ⟨format⟩ may be one of: name (the full name) or shortname (abbreviated name).

week
The week. This may optionally be followed by =number⟩ where ⟨number⟩ is the number of the first week of the calendar.

weekday
The week day number (starting from 0 for Monday). This may optionally be followed by =format⟩ (analogous to month).

day
The two-digit day of the month.

There are three chart elements, which can be created using the following:

\ganttbar[options]{text}{start tss}{end tss}

This creates a bar indicating the duration of a task or subtask.

\ganttgroup[options]{text}{start tss}{end tss}

This combines several subtasks into a single task. For the above two commands, ⟨start tss⟩ indicates the starting time slot and ⟨end tss⟩ indicates the end time slot for the task or task group.

\ganttmilestone[options]{text}{tss}

This indicates that a milestone has been completed on the time slot given by ⟨tss⟩.

If you want to have links between each of these elements (that is, lines drawn from the end of one element to the start of the next element) you can use one of the following commands, analogous to the above three commands.

\ganttlinkedbar[options]{text}{start tss}{end tss}

for an individual task or subtask,

\ganttlinkedgroup[options]{text}{start tss}{end tss}

for a group, or

\ganttlinkedmilestone[options]{text}{tss}

for a milestone.

Example 63. A Gantt Chart

This example is for a Gantt chart that spans a whole year. In this case a day as the time slot would produce a chart that's far too wide, so I've used the compress calendar option and I set the x unit to 8 mm. The pgfgantt manual recommends an x/y ratio of approximately 1:2 so I've also set both y unit title and y unit chart to 16 mm. The newline shortcut option allows me to use \\ instead of \ganttnewline.

\documentclass{article}

\usepackage{pgfgantt}

\begin{document}

\begin{ganttchart}
 [time slot format=isodate,%
  newline shortcut,%
  x unit=8mm,%
  y unit title=16mm,%
  y unit chart=16mm,%
  compress calendar%
  ]% options
 {2014-1-1}% start time slot
 {2014-12-31}% end time slot
\gantttitlecalendar{year,month=shortname}\\
\ganttgroup{Ray Gun Project}{2014-1-1}{2014-06-30}\\
\ganttbar{Design}{2014-1-1}{2014-04-15}\\
\ganttbar{Testing}{2014-04-01}{2014-06-30}\\
\ganttmilestone{Prototype Ready}{2014-07-01}\\
\ganttgroup{Telepathic Cakes}{2014-5-10}{2014-12-31}\\
\ganttbar{Development}{2014-5-10}{2014-12-31}
\end{ganttchart}

\end{document}

This produces the chart shown in Figure 12.11. You can download or view this example.

Figure 12.11: A Gantt Chart
 
Image of a Gantt chart. The chart is inside a box with labels to the left of the box. The top row of the chart has the year 2014 (bordered). The second row is blank. The third row has the abbreviated month names each enclosed in a box. The ray gun project has a filled black bar extending from the start of Jan to the end of Jun with filled downward pointing triangles at either end of the lower side of the bar. The design bar is an unfilled rectangle with a black border extending from the start of Jan to the end of Apr. The testing bar is an unfilled rectangle with a black border extending from the start of Apr to the end of Jun. The prototype ready row has a black diamond with its mid point on the border of Jul and Aug. The telepathic cakes bar is a filled black rectangle that extends from the start of May to the end of Dec with downward pointing filled triangles at the start and end of the lower edge of the bar. The development bar is an unfilled rectangle with a black border extending from the start of May to the end of Dec.

                 ┌───────────────────────────────────────────────────────────────────────┐
                 │                                2014                                   │
                 ├───────────────────────────────────────────────────────────────────────┤
                 │                                                                       │
                 ├─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┤
                 │ Jan │ Feb │ Mar │ Apr │ May │ Jun │ Jul │ Aug │ Sep │ Oct │ Nov │ Dec │
                 ├─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┤
Ray Gun Project  │▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃                                    │
                 │                                                                       │
                 │                                                                       │
                 ├───────────────────────┐                                               │
          Design │                       │                                               │
                 ├───────────────────────┘                                               │
                 │                                                                       │
                 │                 ┌─────────────────┐                                   │
         Testing │                 │                 │                                   │
                 │                 └─────────────────┘                                   │
                 │                                                                       │
 Prototype Ready │                                         ◆                             │
                 │                                                                       │
                 │                                                                       │
Telepathic Cakes │                       ▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃│
                 │                                                                       │
                 │                       ┌───────────────────────────────────────────────┤
     Development │                       │                                               │
                 │                       └───────────────────────────────────────────────┤
                 └───────────────────────────────────────────────────────────────────────┘
End of Image.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs