# Reduce space between title and bars in pgfgantt

I think the space between title and bars in pgfgantt is too big. Is there a way to reduce it? For example, this code

\begin{ganttchart}[ x unit = 0.30cm,
y unit chart = 1.3cm,
hgrid,
vgrid={draw=none,dotted},
time slot format = isodate-yearmonth,
compress calendar,
today=2014-4,
]{2013-05}{2017-02}
\gantttitle{2013}{8}
\gantttitlelist{2014,2015,2016}{12}
\gantttitle{2017}{2}\\
\gantttitlelist[title label font=\tiny ,y unit title = 0.7cm]{5,...,12}{1}
\gantttitlelist[title label font=\tiny ,y unit title = 0.7cm]{1,...,12}{1}
\gantttitlelist[title label font=\tiny ,y unit title = 0.7cm]{1,...,12}{1}
\gantttitlelist[title label font=\tiny ,y unit title = 0.7cm]{1,...,12}{1}
\gantttitlelist[title label font=\tiny ,y unit title = 0.7cm]{1,2}{1}\\
\end{ganttchart}


renders a picture with a too large space between the months and the tasks... making it difficult to read. Is there a way? Thanks

• Don't use \\ at the end of titlelist line. – Ignasi Feb 26 '14 at 19:47
• Don't consider my previous comment. I leave it for completion. Please, read the answer to better understand why it worked and why not to use it as a solution. – Ignasi Feb 28 '14 at 11:21

Gantt charts a, b and c use next declaration:

\begin{ganttchart}[ x unit = 0.30cm,
y unit chart = 1.2cm,
y unit title = 1.2cm,
hgrid={ultra thick,draw},
time slot format = isodate-yearmonth,
compress calendar,
title/.append style={opacity=.5},
]{2013-05}{2013-12}


The important parameter is y unit title (in your example is not explicitly declared, then fixed to its default value: 1cm). This parameter fixes the height of every title bar.

To better understand what happens, I've also drawn some red lines with distance 1.2 cm (y unit title) between them.

\gantttitle[title/.append style={fill=blue!15}]{2013}{8}\\
\gantttitlelist[title/.append style={fill=green!15},title label font=\tiny]{5,...,12}{1}\\


Previous four lines where used to draw figure a. As you can see, first title bar is placed at top most point, second bar is placed y unit title units below top most point because \\ after first \gantttitle declares/counts a newline. And first \ganttbar is placed 2*y unit title units below top point because \\ after second title line adds a new line to the counter.

The white space between title bars and between title bar and first task bar is due to difference between y unit title and title height. This value is used to fix title node's height which by default is 0.6*y unit height.

Therefore if you don't want any white space between titles and task bars you need to use title height=1. The result will be similar to figure d. (In this case I've also declared y unit title=0.6cm.)

Figures b and c will help to understand what happens when we play with local y unit height as in your example or with \\ as in my comment. Code for figure b is:

\gantttitle[title/.append style={fill=blue!15}]{2013}{8}\\
\gantttitlelist[title/.append style={fill=green!15}, title label font=\tiny,
y unit title=.8cm]{5,...,12}{1}\\


I've kept \\ after second title but included y unit title=0.8cm in its options. As you can see this second title is placed y unit title units below origin, but now this value is local 0.8 cm instead of global 1.2 cm. This second title bar is overlapping the first one. But, because \\ is used after second title bar, the first task bar is still placed 2*y unit title global units below origin, leaving a lot of white space before first task bar.

Figure c was drawn with next code:

\gantttitle[title/.append style={fill=blue!15}]{2013}{8}\\
\gantttitlelist[title/.append style={fill=green!15},title label font=\tiny,
y unit title=.6cm]{5,...,12}{1}


There are two differences with code used in figure b. First one is y unit title=0.6cm in second title bar options. This short value makes more evident how second bar is overlapping the first one.

A second difference is missing \\ after second title bar. The result is that the code has only counted one title bar and first task bar is placed only 1.2 cm below origin, but because second title bar is misplaced due to local y unit title value the result could be sometimes acceptable. This is the reason for my comment, which worked with your particular example but won't solve the real problem.

Therefore, the solution to avoid (or reduce) white space between titles and first task is selecting a good value for title height. With title height=1, title node will have y unit title height. The default value is 0.6, therefore 0.4*y unit title is white space between title bar and task bar.

The complete code used for the example figure was:

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfgantt}
\begin{document}

\begin{tikzpicture}
\begin{ganttchart}[ x unit = 0.30cm,
y unit chart = 1.2cm,
y unit title = 1.2cm,
hgrid={ultra thick,draw},
time slot format = isodate-yearmonth,
compress calendar,
title/.append style={opacity=.5},
%                    today=2014-4,
]{2013-05}{2013-12}
\gantttitle[title/.append style={fill=blue!15}]{2013}{8}\\
\gantttitlelist[title/.append style={fill=green!15},
title label font=\tiny]{5,...,12}{1}\\
\end{ganttchart}
\foreach \i in {0,...,4}
\draw[thin, red] (-.5,-\i*1.2cm)-- ++(0:3.5);
\node[above] at (1.25,0) {a)};

\begin{scope}[xshift=4cm]
\begin{ganttchart}[ x unit = 0.30cm,
y unit chart = 1.2cm,
y unit title = 1.2cm,
hgrid={ultra thick,draw},
time slot format = isodate-yearmonth,
title/.append style={opacity=.5},
compress calendar,
]{2013-05}{2013-12}
\gantttitle[title/.append style={fill=blue!15}]{2013}{8}\\
\gantttitlelist[title/.append style={fill=green!15},
title label font=\tiny,
y unit title=.8cm]{5,...,12}{1}\\
\end{ganttchart}
\foreach \i in {0,...,4}
\draw[thin, red] (-.5,-\i*1.2cm)-- ++(0:3.5);
\node[above] at (1.25,0) {b)};
\end{scope}

\begin{scope}[xshift=8cm]
\begin{ganttchart}[ x unit = 0.30cm,
y unit chart = 1.2cm,
y unit title = 1.2cm,
hgrid={ultra thick,draw},
time slot format = isodate-yearmonth,
title/.append style={opacity=.5},
compress calendar,
]{2013-05}{2013-12}
\gantttitle[title/.append style={fill=blue!15}]{2013}{8}\\
\gantttitlelist[title/.append style={fill=green!15},
title label font=\tiny,
y unit title=.6cm]{5,...,12}{1}
\end{ganttchart}
\foreach \i in {0,...,4}
\draw[thin, red] (-.5,-\i*1.2cm)-- ++(0:3.5);
\node[above] at (1.25,0) {c)};
\end{scope}

\begin{scope}[xshift=12cm]
\begin{ganttchart}[ x unit = 0.30cm,
y unit chart = 1.2cm,
y unit title = 0.6cm,
title height=1,
hgrid={ultra thick,draw},
time slot format = isodate-yearmonth,
title/.append style={opacity=.5},
compress calendar,
]{2013-05}{2013-12}
\gantttitle[title/.append style={fill=blue!15}]{2013}{8}\\
\gantttitlelist[title/.append style={fill=green!15},
title label font=\tiny]{5,...,12}{1}\\

• TL;DR: add y unit title = 0.6cm, title height=1, – iled Jan 27 '18 at 2:08