1

I have essentially survival-type data, and I am trying to show the survival duration for each of four groups. I have end-point data, and I need to go backwards from the last date to show when each cohort entered the data. The snippet of code below contains the entire set of information I need in my chart, rather than being a toy example.

I thought a Gantt chart might be the best format - the 4 years across the top, and then add in the four cohorts. I am damned if I can do this. Note that I am working in a dark mode in my editor, to save my eyes, so the images are shown light on dark.

My latest attempt:

\documentclass[article]
\begin{document}

\begin{ganttchart}[
 expand chart =\textwidth,
 y unit title = .5 cm,
 y unit chart = .5 cm,
 hgrid
 ]{1}{4}
\gantttitle{Possible year of school exit}{4}\\
\gantttitle{2009}{1}
\gantttitle{2010}{1}
\gantttitle{2011}{1}
\gantttitle{2012}{1} \\
\ganttbar{}{15-year-olds}{4} \\
\ganttbar{}{16-year-olds}{3,4} \\
\ganttbar{}{17-year-olds}{2,3,4} \\
\ganttbar{}{15-year-olds}{1,2,3,4} \\

\end{ganttchart}
\end{document}

What I end up with: Image of bad Gantt chart with zero bars

The width is correctly across the page, but no bars are showing. It also doesn't work when I try to put the years into the \ganttbar instead of 1, 2, 3, and/or 4.

Another problem is that the text, that is showing, is too high for the title box (I would like to make the box larger vertically as the text is the correct font size).

The chart is too wide, so I tried to change the width to how I specify when I bring in PDF images, and that went bad as well:

expand chart =.8

gave

Still bad, wrong width

I seem to have some horizontal lines, but neither contain any text. The years are also backwards.

What do I need to do to modify the code so that I can get my nice little Gantt chart? I also tried to put it into a figure environment so that I could add a label and caption (which I need) and that went badly as well. I have the manual, and can't see what I am doing wrong.

Edit 1: update

I have changed to this code, but I still can't get the bars to show, and the height of the cells is still too small relative to the font size.

\begin{figure}
\begin{ganttchart}[
x unit = 1.5cm,
y unit title = .5 cm,
y unit chart = .5 cm,
vgrid
]{1}{4}
\gantttitle{Possible year of school exit}{4}\\
\gantttitle{2009}{1}
\gantttitle{2010}{1}
\gantttitle{2011}{1}
\gantttitle{2012}{1} \\
\ganttbar{}{15-year-olds}{4}{4} \\
\ganttbar{}{16-year-olds}{3}{4} \\
\ganttbar{}{17-year-olds}{2}{4} \\
\ganttbar{}{15-year-olds}{1}{4} \\

\end{ganttchart}
\end{figure}

Which gives me:

Third attempt at the Gantt chart

1 Answer 1

1

\ganttbar takes three arguments, not four. Remove the first, empty one.

enter image description here

\documentclass{article}
\usepackage{pgfgantt}
\begin{document}

\begin{ganttchart}[
x unit = 1.5cm,
y unit title = .5 cm,
y unit chart = .5 cm,
vgrid
]{1}{4}
\gantttitle{Possible year of school exit}{4}\\
\gantttitle{2009}{1}
\gantttitle{2010}{1}
\gantttitle{2011}{1}
\gantttitle{2012}{1} \\
\ganttbar{15-year-olds}{4}{4} \\
\ganttbar{16-year-olds}{3}{4} \\
\ganttbar{17-year-olds}{2}{4} \\
\ganttbar{15-year-olds}{1}{4} \\

\end{ganttchart}
\end{document}
2
  • Thanks, I had looked at numerous answers and had managed to get myself very lost. How can I increase the vertical space in the two title rows so that the words/numbers don't touch the bottom and top margins? The font size works well, I have been unable to find instructions on how to do that. The examples in the manual seem to work perfectly without any margin spacing instructions. For some reason, mine aren't. :(
    – Michelle
    Commented Sep 19, 2021 at 10:53
  • 1
    @Michelle LaTeX does what you tell it to do, namely y unit title = .5 cm. Increase 0.5cm or remove the line.
    – gernot
    Commented Sep 19, 2021 at 14:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .