Differences

This shows you the differences between two versions of the page.

05Misc:A_LaTeX_package_for_gantt_plots [2017/09/26 11:01] (current)
Line 1: Line 1:
 +======= A LaTeX package for drawing gantt plots using pgf =======
 +<html>
 +<h3>Introduction</h3>
 +<p>
 +I was searching for a LaTeX package or macros for drawing <a href="http://en.wikipedia.org/wiki/Gantt_chart" target="_blank">gantt charts</a>. I found the <a href="http://www.ctan.org/tex-archive/graphics/pstricks/contrib/pst-gantt/" target="_blank">pst-gantt</a> package but it was nasty using PS Tricks together with pdflatex. So I wrote a small package using <a href="http://sourceforge.net/projects/pgf/" target="_blank">pgf/tikz</a>.
 +</p>
 +<p align="center"><br><a href="/tex/gantt.sty">Download gantt.sty package</a><br><br></p>
 +<p>
 +<h3>Note: The gantt package is also available in the Arch Linux distribution</h3>
 +For package information, look here: <a href="https://aur.archlinux.org/packages/texlive-gantt">https://aur.archlinux.org/packages/texlive-gantt/</a><br><br>
 +<h3>Note: It seems that the gantt package inspired the development of the CTAN pgfgantt package</h3>
 +The CTAN package can be found here: <a href="https://www.ctan.org/pkg/pgfgantt?lang=de">https://www.ctan.org/pkg/pgfgantt?lang=de</a><br><br>
 +<h3>Update 20.03.2011, Version 1.3</h3>
 +Andr&eacute;s Silva Marambio (see his <a href="http://linux-productivo.blogspot.com/2011/03/some-improvements-for-ganttsty-file-for.html" target="_blank">BLOG</a>) enhanced the package by adding milestones (\ganttmilestone and \ganttmilestonecon) and a fixed a bug using \ganttbarcon (thanks to Andr&eacute;s!)<br><br>
 +<h3>Update 15.03.2011, Version 1.2</h3>
 +Some problems of the package has been discussed and identified at
 +<a href="http://tex.stackexchange.com/questions/8819/conflict-between-gantt-sty-and-framebox">tex.stackexchange.com</a>
 +and fixed by Alan Munn. Theese changes are:<br>
 +<ul>
 +<li>px sizes has ben changed ot pt due to problems with some LaTeX distributions (thanks to Michael Kubovy, Lo&iuml;c Le Guyader)</li>
 +<li>Correction of the text aligned in \titleelement (thanks to Josh Hykes!)</li>
 +<li>\unitlength was changed to \ganttunitlength</li>
 +<li>\RequirePackage was added</li>
 +</ul><br><br>
 +<h3>Update 05.08.2010, Version 1.1</h3>
 +\ganttbar and \ganttbarcon have been extended with the xkeyval syntax<br>
 +The pattern of the bar is now independent of the color and can be set by <br>
 +e.g. \ganttbar[pattern=horizontal lines,color=blue]{...}{1}{1}<br>
 +This syntax is now incompatible with the previous ones! Replace \ganttbar[<pattern>] with \ganttbar[pattern=<pattern>]!<br>
 +<br>
 +Old Versions: <a href="/tex/gantt_v1.0.sty">gantt_v1.0.sty</a>, <a href="/tex/gantt_v1.1.sty">gantt_v1.1.sty</a>, <a href="/tex/gantt_v1.2.sty">gantt_v1.2.sty</a>.
 +</p><br><br>
 +<h3>Package Description</h3>
 +<p>
 +In the following you will find a short description of environments and commands: <br>
 +<br>
 +The <b>gantt</b> environment draws the canvas of a gantt figure (realized as tikzpicture)<br>
 +The usage is \begin{gantt}[...]{no of Tasks to plot}{no of time slots}<br>
 +The optional argument [...] can be filled in a key=value syntax, using one or more of the following keys:<br>
 +<br>
 +xunitlength - length of one time slot (default: 1 cm)<br>
 +fontsize - fontsize of labels (default: \normalsize)<br>
 +titlefontsize - fontsize of title section (default: \small)<br>
 +drawledgerline  - Switch to enable/disable the drawing of horizontal ledger lines (default value: false)<br>
 +<br>
 +<b>ganttitle</b> is the environment for drawing the title section<br>
 +<br>
 +<b>\titleelement</b> draws one element of the title<br>
 +usage: \titleelement{label}{length}<br>
 +<br>
 +<b>\numtitle</b> draws a numbered sequence of title elements<br>
 +usage: \numtitle{start number}{increment}{end number}{length of each title element}<br>
 +<br>
 +<b>\ganttbar</b> draws a single, unconnected bar for representing a task<br>
 +usage: \ganttbar[pattern=&lt;pattern&gt;,color=&lt;color&gt;]{label}{start}{length}<br>
 +where the optional comma separated arguments are:<br>
 +&lt;pattern&gt; - is a tikz pattern (e.g. north west lines (default), north east lines, crosshatch, crosshatch dots, grid, ...)<br>
 +&lt;color&gt; - a tikz color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br>
 +for more information see the tikz documentation<br>
 +<br>
 +<b>\ganttcon</b> draws an arrow between to bars with specified coordinates<br>
 +usage: \ganttbar{startx}{starty}{endx}{endy}<br>
 +<br>
 +<b>\ganttbarcon</b> draws a single bar *and* connects the bar with the previous bar (or milestone) for consecutive tasks<br>
 +usage: \ganttbar[pattern=&lt;pattern&gt;,color=&lt;color&gt;]{label}{start}{length}<br>
 +where the optional pattern argument are the same as for \ganttbar<br>
 +<br>
 +<b>\ganttgroup</b> draws a bar to group tasks<br>
 +usage: \ganttgroup{label}{start}{length}<br>
 +<br>
 +<b>\ganttmilestone</b> draws a milestone using a diamond<br>
 +usage: \ganttmilestone[color=&lt;color&gt;]{label}{start}<br>
 +where the optional color argument argument is:<br>
 +&lt;color&gt; - a tikz color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br>
 +<br>
 +<b>\ganttmilestonecon</b> draws a milestone using a diamond *and* connects the milestone with the previous bar or milestone<br>
 +usage: \ganttmilestonecon[color=&lt;color&gt;]{label}{start}<br>
 +where the optional color argument argument is:<br>
 +&lt;color&gt; - a tikz color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br>
 +</p>
 +<h3>Examples</h3>
 +<p>
 +The usage is best explained by some examples.<br>
 +Here is a minimal example:
 +</p>
 +<p>
 +<font class="code">
 +\documentclass{article}<br>
 +<br>
 +\usepackage{tikz}<br>
 +\usepackage{gantt}<br>
 +<br>
 +\begin{document}<br>
 +&nbsp;&nbsp;\begin{gantt}{10}{12}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\begin{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{1}{1}{12}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\end{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar{a task}{0}{2}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbarcon{a consecutive task}{2}{4}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbarcon{another consecutive task}{8}{2}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttmilestone[color=cyan]{Milestone with color!}{4}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar{another task}{2}{2}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar[color=cyan]{another coloured task}{4}{4}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar{another task}{4}{2}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttcon{4}{5}{4}{7}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttmilestonecon{A connected Milestone}{7}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbarcon{another consecutive task}{8}{2}<br>
 +&nbsp;&nbsp;\end{gantt}<br>
 +\end{document}<br>
 +</font>
 +</p>
 +<p>leading to the result:</p>
 +<p align="center"><img width="550" src="/images/gantt_ex1.gif"></p>
 +<p>
 +Here is a similar example using the names of the month's:
 +</p>
 +<p>
 +<font class="code">
 +...<br>
 +&nbsp;&nbsp;\begin{gantt}{7}{12}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\begin{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Jan}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Feb}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Mar}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Apr}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{May}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Jun}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Jul}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Aug}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Sep}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Oct}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Nov}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{Dec}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\end{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar{Task 1}{0}{2}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbarcon{a consecutive task}{2}{4}<br>
 +&nbsp;&nbsp;\end{gantt}<br>
 +...<br>
 +</font>
 +</p>
 +<p>leading to the result:</p>
 +<p align="center"><img width="550" src="/images/gantt_ex2.gif"></p>
 +<p>
 +You can use more titles with diffent length' to divide the time axis:
 +</p>
 +<p>
 +<font class="code">
 +...<br>
 +&nbsp;&nbsp;\begin{gantt}{7}{12}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\begin{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{2010}{1}{2012}{4}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\end{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\begin{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{1}{1}{4}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{1}{1}{4}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{1}{1}{4}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\end{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar{Task 1}{0}{2}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbarcon{a consecutive task}{2}{4}<br>
 +&nbsp;&nbsp;\end{gantt}<br>
 +...<br>
 +</font>
 +</p>
 +<p>leading to the result:</p>
 +<p align="center"><img width="550" src="/images/gantt_ex3.gif"></p>
 +<p>
 +Here is a more complex example using groups, different patterns and the optional arguments:
 +</p>
 +<p>
 +<font class="code">
 +<br>
 +\documentclass{article}<br>
 +<br>
 +\usepackage{gantt}<br>
 +\usepackage{pdflscape}<br>
 +<br>
 +\begin{document}<br>
 +&nbsp;&nbsp;\begin{landscape}<br>
 +&nbsp;&nbsp;\scalebox{0.8}{<br>
 +&nbsp;&nbsp;\begin{gantt}[xunitlength=0.5cm,fontsize=\small,titlefontsize=\small,drawledgerline=true]{10}{48}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\begin{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{2009}{7}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{2010}{1}{2012}{12}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\titleelement{2013}{5}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\end{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\begin{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{6}{1}{12}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{1}{1}{12}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{1}{1}{12}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{1}{1}{12}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\numtitle{1}{1}{5}{1}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\end{ganttitle}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar{task 1}{2}{17}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttgroup{a group of tasks}{6}{18}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar{task 2}{5}{10}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar[pattern=crosshatch,color=blue]{task 3}{15}{3}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar{task 4}{20}{3}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttcon{15}{4}{20}{6}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbar{task 5}{15}{5}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbarcon[color=red]{task 6}{20}{5}<br>
 +&nbsp;&nbsp;&nbsp;&nbsp;\ganttbarcon{task 7}{30}{5}<br>
 +&nbsp;&nbsp;\end{gantt}<br>
 +&nbsp;&nbsp;}<br>
 +&nbsp;&nbsp;\end{landscape}<br>
 +\end{document}<br>
 +</font>
 +</p>
 +<p>leading to the result:</p>
 +<p align="center"><img width="600" src="/images/gantt_ex4.png"></p>
 +</html>
05Misc/A_LaTeX_package_for_gantt_plots.txt · Last modified: 2017/09/26 11:01 (external edit)
 (login)