[Tex/LaTex] How to left align, number the items in a gantt chart

pgfgantttikz-pgf

I want to create a Gantt Chart in latex and I want to aligned the items in the Gantt Chart to the left and to use numbering and sub numbering as well. But, I've not come across such a thing before. It'd be a grate help if anyone could help on this.

Best Answer

A bit of guesswork, and no sub-numbering (whatever exactly you mean by that), but here is a quick example, there are a few explanatory comments in the code, ask if anything is entirely unclear.

output of code

\documentclass[border=5mm]{standalone}
\usepackage{pgfgantt} % for ganttcharts
\usepackage{etoolbox} % for \AtBeginEnvironment

% make a new counter for the line number in a chart
\newcounter{ganttline}
% set the counter to zero at start of every ganttchart environment
\AtBeginEnvironment{ganttchart}{\setcounter{ganttline}{0}}
\begin{document}

\begin{ganttchart}[
  % for each of bar, group, milestone:
  %   - step the line counter
  %   - print the current value of the counter followed by period
  %   - add text of item in the default manner at the end
  bar label text={\refstepcounter{ganttline}\arabic{ganttline}. \strut#1},
  group label text={\refstepcounter{ganttline}\arabic{ganttline}. \strut#1},
  milestone label text={\refstepcounter{ganttline}\arabic{ganttline}. \strut#1},
  % set text in a 5cm wide box, adjust 5cm to your liking
  bar label node/.append style={text width=5cm},
  group label node/.append style={text width=5cm},
  milestone label node/.append style={text width=5cm}
]{1}{12}
\gantttitle{2011}{12} \\
\gantttitlelist{1,...,12}{1} \\
\ganttgroup{Group 1}{1}{7} \\
\ganttbar{Task 1}{1}{2} \\
\ganttlinkedbar{Task 2}{3}{7} \ganttnewline
\ganttmilestone{Milestone}{7} \ganttnewline
\ganttbar{Final Task}{8}{12}
\ganttlink{elem2}{elem3}
\ganttlink{elem3}{elem4}
\end{ganttchart}
\end{document} 

With some lines:

output of code

\documentclass[border=5mm]{standalone}
\usepackage{pgfgantt} % for ganttcharts
\usepackage{etoolbox} % for \AtBeginEnvironment

% make a new counter for the line number in a chart
\newcounter{ganttline}
% set the counter to zero at start of every ganttchart environment
\AtBeginEnvironment{ganttchart}{\setcounter{ganttline}{0}}
\begin{document}

\begin{tikzpicture}
\begin{ganttchart}[
  % for each of bar, group, milestone:
  %   - step the line counter
  %   - print the current value of the counter followed by period
  %   - add text of item in the default manner at the end
  bar label text={\refstepcounter{ganttline}\arabic{ganttline}. \strut#1},
  group label text={\refstepcounter{ganttline}\arabic{ganttline}. \strut#1},
  milestone label text={\refstepcounter{ganttline}\arabic{ganttline}. \strut#1},
  % set text in a 5cm wide box, adjust 5cm to your liking
  % give the node a name that depends on the counter
  % the counter is stepped after the naming, so label0 is the first, label4 is the last
  bar label node/.append style={text width=5cm,name=label\arabic{ganttline}},
  group label node/.append style={text width=5cm,name=label\arabic{ganttline}},
  milestone label node/.append style={text width=5cm,name=label\arabic{ganttline}},
  % the canvas node makes the frame around the chart
  canvas/.append style={name=canvas},
]{1}{12}
\gantttitle{2011}{12} \\
\gantttitlelist{1,...,12}{1} \\
\ganttgroup{Group 1}{1}{7} \\
\ganttbar{Task 1}{1}{2} \\
\ganttlinkedbar{Task 2}{3}{7} \ganttnewline
\ganttmilestone{Milestone}{7} \ganttnewline
\ganttbar{Final Task}{8}{12}
\ganttlink{elem2}{elem3}
\ganttlink{elem3}{elem4}
\end{ganttchart}

% draw a vertical line relative to the top left corner of label0 and bottom left corner of label4
\draw ([xshift=1.3em]label0.north west) -- ([xshift=1.3em]label4.south west);

% draw horizontal lines between the nodes
\foreach [evaluate={\y=int(\x+1)}] \x in {0,...,3}
 {
   % define helper coordinate halfway between the left corners
   \path (label\x.south west) -- coordinate (m\x) (label\y.north west);
   % draw a line from that coordinate to the canvas box
   \draw (m\x) -- (m\x -| canvas.west);
 }
\end{tikzpicture}
\end{document} 
Related Question