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.
[Tex/LaTex] How to left align, number the items in a gantt chart
pgfgantttikz-pgf
Related Solutions
Code (Update)
\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfgantt}
\makeatletter
\ganttset{
prog default/.initial=100,
prog/.code={
\pgfutil@in@{:}{#1}
\ifpgfutil@in@
\pgfqkeysalso{/pgfgantt}{@prog={#1}}
\else
\pgfqkeysalso{/pgfgantt}{@prog={\pgfkeysvalueof{/pgfgantt/prog default}:#1}}
\fi
},
@prog/.code args={#1:#2}{
\pgfqkeysalso{/pgfgantt}{progress=100, progress label text={#2 (#1\,\%)}}
}
}
\makeatother
\ganttset{progress label anchor/.append style={text=red}}
\begin{document}
\begin{ganttchart}[y unit title=0.4cm,
y unit chart=0.5cm,
vgrid={draw=none, dotted},
hgrid,
title label anchor/.style={below=-1.6ex},
title left shift=.05,
title right shift=-.05,
title height=1,
bar/.style={fill=gray!50},
incomplete/.style={fill=white},
progress label text={},
bar height=0.7,
group right shift=0,
group top shift=.6,
group height=.3,
group peaks={}{}{.2},
]{12}
\gantttitle{2012}{12} \\
\gantttitle{October}{4}
\gantttitle{November}{4}
\gantttitle{December}{4} \\
\ganttgroup{Group 1}{1}{8}\\
\ganttbar[prog=50: Resource 1]{Task 1}{1}{2} \\
\ganttbar[prog= Resource 2]{Task 2}{3}{4} \\
\ganttbar[prog= Resource 3]{Task 3}{5}{6}\\
\ganttbar[prog=50: Resource 1, progress label anchor/.append style={below=4pt}]{Task 4}{1}{8} \\
\end{ganttchart}
\end{document}
Output
Code
\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfgantt}
\makeatletter
\ganttset{
prog default/.initial=100,
prog/.code={
\pgfutil@in@{:}{#1}
\ifpgfutil@in@
\pgfqkeysalso{/pgfgantt}{@prog={#1}}
\else
\pgfqkeysalso{/pgfgantt}{@prog={\pgfkeysvalueof{/pgfgantt/prog default}:#1}}
\fi
},
@prog/.code args={#1:#2}{
\edef\pgf@tempa{#1}%
\ifx\pgf@tempa\tikz@nonetext
\pgfqkeysalso{/pgfgantt}{progress={100},progress label text={#2}}
\else
\pgfqkeysalso{/pgfgantt}{progress={#1},progress label text={#2 (##1\,\%)}}
\fi
}
}
\makeatother
\ganttset{progress label anchor/.append style={text=red}}
\begin{document}
\begin{ganttchart}[y unit title=0.4cm,
y unit chart=0.5cm,
vgrid={draw=none, dotted},
hgrid,
title label anchor/.style={below=-1.6ex},
title left shift=.05,
title right shift=-.05,
title height=1,
bar/.style={fill=gray!50},
incomplete/.style={fill=white},
progress label text={},
bar height=0.7,
group right shift=0,
group top shift=.6,
group height=.3,
group peaks={}{}{.2},
]{12}
\gantttitle{2012}{12} \\
\gantttitle{October}{4}
\gantttitle{November}{4}
\gantttitle{December}{4} \\
\ganttgroup{Group 1}{1}{8}\\
\ganttbar[prog=50: Resource 1]{Task 1}{1}{2} \\
\ganttbar[prog= Resource 2]{Task 2}{3}{4} \\
\ganttbar[prog=none:Resource 3]{Task 3}{5}{6}\\
\ganttbar[prog=50: Resource 1, progress label anchor/.append style={below=4pt}]{Task 4}{1}{8} \\
\end{ganttchart}
\end{document}
Output
This answer sets up two new Gantt chart elements using the \newganttchartelement*
macro. It takes a single optional argument and two mandatory arguments <label>
and the time slot, <tss>
. It operates the same way as does the \milestone
macro. The newgantchartelement
named lresource can be used to set a node on the left of the task to define the corresponding resource. tss
can be given by a value >=1 less than the tss for the corresponding task. For left placed resources, the resource must be specified before the task. The same logic applies to rresource newganttchartelement, except that it sets the resource on the right of the corresponding task. In this case, the resource must be specified after the task.
Regarding the OP's question about setting [inline=false]
globally for ganttbar
, this may not be possible. The manual says in section 2.2:
Since pgfgantt uses the pgfkeys package for key management, all its keys reside in the /pgfgantt/ path.
My interpretation of this statement is that having set inline=true
for the lresource and rresource, that setting operates globally until it is specifically reset in each ganttbar
by writing ganttbar[inline=false]
.
This is the result, with the ganttbar[inline=false]
:
Here is the MWE, with some additional comments in the code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pdflscape}
\usepackage{pgfgantt}
\pagestyle{empty}
\newganttchartelement*{lresource}{ % The starred version mimics a milestone element with 2 options
lresource/.style={}, % Don't draw the node
inline=true,
lresource inline label node/.style={anchor=east,font=\bfseries\itshape\color{blue}},
lresource left shift=0ex,
lresource right shift=0ex
}
\newganttchartelement*{rresource}{
rresource/.style={},
inline=true,
rresource inline label node/.style={anchor=west,font=\bfseries\itshape\color{blue}},
rresource left shift=0ex,
rresource right shift=0ex
}
\begin{document}
\begin{landscape}
\begin{ganttchart}[
hgrid,
vgrid={draw=none, draw=none, dotted},
progress=100,
progress label text={}]%
{1}{36}
\gantttitle{Y1}{12} \gantttitle{Y2}{12} \gantttitle{Y3}{12} \\
\gantttitlelist{1,...,36}{1} \\
\ganttlresource{resource}{5} % Make the tss value one less than the start of Task 1
\ganttbar[inline=false]{Task1}{6}{10} \\
\ganttlresource{resource}{31} % Make the tss value one less than the start of Task 2
\ganttbar[inline=false]{Task2}{32}{36} \\
\ganttbar[inline=false]{Task3}{15}{19}
\ganttrresource{resource}{20} % Make the tss value one more than the end of Task 3
\end{ganttchart}
\end{landscape}
\end{document}
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.
With some lines: