[Tex/LaTex] Gantt chart by pgfgantt 4.0 – problem with tiltes

pgfgantt

I don't know what I am doing wrong. I am trying to customise Gantt chart using pgfgantt package. I have done some research and read the manual but I am completely puzzled by the results. I cannot seem to understand what is actually happening.

enter image description here

I would like to do the following:

  • make the main title centred; sorted, see edit,
  • decrease space between all title,
  • decrease size of first up to third title,
  • increase size of the fourth title (with week dates),
  • and finally rotate labels in the last title so the week in form day/month would fit in cells.

The huge problem is the title spacing and sizing! I tried to read the manual, tried to figure it out by myself but on this stage it is just too complex to understand. I would appreciate any help with that. Thanks

Below is the MWE to show my results on the picture. I use pgfgantt v 4.0 which I believe is not compatible with previous versions.

\documentclass[a4paper,landscape]{article}

\usepackage{graphicx}
\usepackage[a4paper, landscape, margin=0.5in]{geometry}
\usepackage[usernames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pgfgantt}
\ganttset{calendar week text={\small{\startday/\startmonth}}}

\begin{document}
\begin{figure}[h!bt]
\begin{center}
\begin{ganttchart}[
    hgrid,
    vgrid={*6{draw=none}, dotted},
    bar/.append style={fill=black},
    bar incomplete/.append style={fill=white},
    time slot format=isodate,
    time slot format/base century=2000,
    x unit=0.062cm,
    y unit chart=0.6cm,
    bar top shift=0.1,
    bar height=0.8,
    title label font=\bfseries\normalsize,
    time slot format/start date=2018-01-01]{2018-01-01}{2018-12-30}
\gantttitle[y unit title=1cm, title height=0.75]{TITLE}{0}{52}\\
\gantttitlecalendar[y unit title=1cm, title height=0.75]{year, month=shortname}\\
\gantttitlecalendar[y unit title=1cm, title height=0.75]{week}\\
\ganttbar{Short}{2018-01-01}{2018-01-15}\\
\ganttbar{Widerrr}{2018-01-16}{2018-02-28}\\
\ganttbar{Long long long long }{2018-03-01}{2018-05-31}\\
\ganttbar{Midium long}{2018-06-01}{2018-08-31}\\
\ganttbar{Project X}{2018-09-01}{2018-12-30}
\end{ganttchart}
\end{center}
\end{figure}
\end{document}

EDIT.

I found a bug in the code. To centre title I only need to provide a number of all cells in a row:

 \gantttitle{TITLE}{364}

Best Answer

The gap between the title line is determined by y unit title, which is the height of the title plus the gap, and title height, which is the ratio of the first used for the title. E.g. y unit title=1cm and title height=0.75 leads to a 0.25cm heigh gap. Setting title height=1 will therefore remove the gap.

Since the title line for the weeks is higher, it would overlap with the bars. Therefor I added an invisible title line using the option title/.style={opacity=0} to make room for it.

The lables in a title line can be rotated with the option title label node/.append style={rotate=90}.

This results in:

enter image description here

The code:

\documentclass[a4paper,landscape]{article}

\usepackage{graphicx}
\usepackage[a4paper, landscape, margin=0.5in]{geometry}
\usepackage[usernames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pgfgantt}
\ganttset{calendar week text={\small{\startday/\startmonth}}}

\begin{document}
\begin{figure}[h!bt]
\begin{center}
\begin{ganttchart}[
    hgrid,
    vgrid={*6{draw=none}, dotted},
    bar/.append style={fill=black},
    bar incomplete/.append style={fill=white},
    time slot format=isodate,
    time slot format/base century=2000,
    x unit=0.062cm,
    y unit chart=0.6cm,
    y unit title=0.6cm, % height of title line and gap
    title height=1, % use full height for title, leaving no gap
    bar top shift=0.1,
    bar height=0.8,
    title label font=\bfseries\normalsize,
    time slot format/start date=2018-01-01]{2018-01-01}{2018-12-30}
\gantttitle{TITLE}{364}\\
\gantttitlecalendar{year, month=shortname}\\
%                   increase height   rotate label
\gantttitlecalendar[title height=1.8, title label node/.append style={rotate=90}]{week}\\
\gantttitle[title/.style={opacity=0}]{}{364}\\ % invisible title to make room for previous higher line
\ganttbar{Short}{2018-01-01}{2018-01-15}\\
\ganttbar{Widerrr}{2018-01-16}{2018-02-28}\\
\ganttbar{Long long long long }{2018-03-01}{2018-05-31}\\
\ganttbar{Midium long}{2018-06-01}{2018-08-31}\\
\ganttbar{Project X}{2018-09-01}{2018-12-30}
\end{ganttchart}
\end{center}
\end{figure}
\end{document}