Monday, November 3, 2014

Drawing Gantt Charts using Latex

While preparing some document in last week, I wanted to draw a Gantt chart to visualize a time line of a project. I tried different GUI based tools but I didn't like  them. At the end, I decided to find out whether there's any Latex package available to get my task done. Luckily, I found it. For this purpose, first of all, we need to have a style file called gantt.sty which you can download from here. Then we need to compose our gantt  chart definition in a .tex file. Following is such an example gantt chart definition which I saved with the file name my_gantt_chart.tex in the same directory as the style file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
\documentclass{article}

\usepackage[pdftex,active,tightpage]{preview} \setlength\PreviewBorder{2mm}
\usepackage{gantt}

\begin{document}
\begin{preview}

\begin{gantt}{7}{12}
    \begin{ganttitle}
      \titleelement{\textbf{Year 2015}}{12}
    \end{ganttitle}
    \begin{ganttitle}
      \titleelement{\textbf{Jan}}{1}
      \titleelement{\textbf{Feb}}{1}
      \titleelement{\textbf{Mar}}{1}
      \titleelement{\textbf{Apr}}{1}
      \titleelement{\textbf{May}}{1}
      \titleelement{\textbf{Jun}}{1}
      \titleelement{\textbf{Jul}}{1}
      \titleelement{\textbf{Aug}}{1}
      \titleelement{\textbf{Sep}}{1}
      \titleelement{\textbf{Oct}}{1}
      \titleelement{\textbf{Nov}}{1}
      \titleelement{\textbf{Dec}}{1}
    \end{ganttitle}
    \ganttbar[color=green]{\textbf{Phase-1: Design and prototype implementation}}{0}{3}
    \ganttbarcon[color=blue]{\textbf{Phase-2: Pilot deployment and field trials}}{3}{6}
    \ganttbarcon[color=red]{\textbf{Phase-3: Full scale deployment and evaluations}}{9}{3}
  \end{gantt}
\end{preview}
\end{document}

Now we can generate the PDF file by issuing  the  following command in the terminal.

pdflatex my_gantt_chart.tex

Following is a screenshot of the output PDF I received.

Even though the output doesn't look fancy as the output of many other tools, I'm happy with this because it allows  me to prepare it using Latex, my favorite document processing tool.

References:




No comments:

Post a Comment