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}\\
\ganttbar{Task 1}{2013-05}{2014-08}\\
\ganttbar{Task 2}{2013-12}{2015-05}\\
\ganttbar{Task 3}{2014-12}{2016-11}
\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
Best Answer
Let's start with an example:
Gantt charts a, b and c use next declaration:
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 everytitle bar
.To better understand what happens, I've also drawn some red lines with distance 1.2 cm (
y unit title
) between them.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 placed2*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
andtitle height
. This value is used to fixtitle node's height
which by default is0.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 declaredy 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:I've kept
\\
after second title but includedy unit title=0.8cm
in its options. As you can see this second title is placedy 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 placed2*y unit title
global units below origin, leaving a lot of white space before first task bar.Figure c was drawn with next code:
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 localy 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
. Withtitle height=1
, title node will havey 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: