Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to create a Gantt chart, and found this wonderful package pgfgantt. However, my labels do not get properly centered in the boxes. Am I doing something wrong? Is there a way to get the result I want? (I looked around for an answer, but could not find it. My apologies if I missed it.)

Here is the code:

\documentclass{standalone}
\usepackage{pgfgantt}
\definecolor{grey}{gray}{0.75}
\begin{document}
\begin{ganttchart}[hgrid, inline, bar height = 1, bar top shift = 0, x unit = .7cm, y unit chart= .4cm]{17}
\ganttbar[bar/.style={fill=grey}]{\ }{0.00000}{1.00000}
\ganttbar{1}{1.00000}{2.00000}
\ganttbar[bar/.style={fill=grey}]{\ }{2.00000}{3.00000}
\ganttbar{4}{3.00000}{8.00000}
\\
\ganttbar[bar/.style={fill=grey}]{\ }{0.00000}{1.00000}
\ganttbar{2}{1.00000}{3.00000}
\ganttbar[bar/.style={fill=grey}]{\ }{3.00000}{4.00000}
\ganttbar{5}{4.00000}{15.00000}
\\
\ganttbar[bar/.style={fill=grey}]{\ }{0.00000}{1.00000}
\ganttbar{3}{1.00000}{4.00000}
\ganttbar[bar/.style={fill=grey}]{\ }{4.00000}{5.00000}
\ganttbar{6}{5.00000}{17.00000}
\end{ganttchart}
\end{document}

I cannot post the resulting pdf, because I'm a new user, but maybe you can still see it here

share|improve this question
    
Would the option bar label inline anchor/.style=left satisfy you? You should use it as \ganttbar[bar label inline anchor/.style=left]{1}{1.00000}{2.00000}. –  Claudio Fiandrino Aug 6 '12 at 9:36
    
Thanks for your reply. I would really like the labels to be centered, though. –  fff Aug 6 '12 at 9:53
add comment

1 Answer

up vote 5 down vote accepted

The alignment is correctly centered, but the ganttbars that you create are overlapping. The numbers in the second and third argument of \ganttbar represent a kind of slot value and are not (x)-coordinates. See the following corrected MWE:

\documentclass{standalone}
\usepackage{pgfgantt}
\definecolor{grey}{gray}{0.75}
\begin{document}
\begin{ganttchart}[hgrid, inline, bar height = 1, bar top shift = 0, x unit = .7cm, y unit chart= .4cm]{17}
\ganttbar[bar/.style={fill=grey}]{}{1}{1} % starts in slot 1, ends in slot 1, width=1 slot
\ganttbar{1}{2}{3}                        % starts in slot 2, ends in slot 3, width=2 slots
\ganttbar[bar/.style={fill=grey}]{}{4}{4} % starts in slot 4, ends in slot 4, width=1 slot
\ganttbar{3}{5}{8.00000}                  % starts in slot 5, ends in slot 8, width=4 slots
 \ganttnewline
\ganttbar[bar/.style={fill=grey}]{}{1}{1}
\ganttbar{2}{2}{3}
\ganttbar[bar/.style={fill=grey}]{}{4}{4}
\ganttbar{5}{5}{15}
 \ganttnewline
\ganttbar[bar/.style={fill=grey}]{}{1}{1}
\ganttbar{3}{2}{4}
\ganttbar[bar/.style={fill=grey}]{}{5}{5}
\ganttbar{6}{6}{17}
\end{ganttchart}
\end{document} 

ganttbar example

share|improve this answer
    
Thanks a lot! I had a feeling I was just doing something wrong, but I could not figure out what! –  fff Aug 6 '12 at 9:58
1  
Wolfgang Skala (the author of pgfgantt) replied to my question by email as well today. He pointed out the time slot modifier optional argument of the ganttchart environment. Setting this argument to 0 will treat the numbers as x-coordinates. –  fff Aug 7 '12 at 12:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.