2

I have a gantt-chart in which I would the Title to be included in the canvas, meaning that I have several titles within my chartt that should work as sections. I would like to have Title in the center above the task descriptions and the bars.

This is what I have so far:

\documentclass[a4paper, 11pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb} % amsmath loads amstext
\usepackage[english, ngerman]{babel}
\usepackage[hmargin=2.5cm,vmargin=2.5cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfgantt}

\begin{document}

\begin{center}

\begin{tikzpicture} % added

\begin{ganttchart}[%
    x unit=0.8cm,
    y unit title=0.8cm,
    y unit chart=0.6cm,
    vgrid,
    hgrid,
    bar/.append style={fill=MidnightBlue},
    milestone/.append style={fill=SkyBlue, rounded corners=3pt},
    bar label font=\footnotesize, % reduce font size
    milestone label font=\footnotesize\itshape, % reduce font size
    bar label node/.append style={align=right},
    milestone label node/.append style={align=right}, 
    canvas/.append style={name=canvas}
]{1}{12}

\gantttitle{\textbf{YEAR 1}: Entry Phase}{12} \\
\gantttitlelist{1,...,12}{1} \\
\ganttbar{Literature: research and review}{1}{7} \\
\ganttbar{Writing of exposé}{4}{6} \\
\ganttmilestone{Public presentation}{7} \\
\ganttbar{Adaption of experiment 1}{11}{12} \\
\ganttbar{Conference participation\\\& networking}{11}{12} \\ % <- added a linebreak in the label text

\makeatletter
\advance\gtt@currentline by 1
\makeatother

\gantttitle{\textbf{YEAR 2}: Research Phase}{12} \\
\gantttitlelist{1,...,12}{1} \\

\makeatletter
\advance\gtt@currentline by -2
\makeatother

\ganttbar{Experiment 1: conduction}{1}{2} \\
\ganttbar{Planning of experiment 2}{3}{4} \\
\ganttbar{Organizing a workshop}{9}{11} \\
\ganttmilestone{Workshop}{11}

\end{ganttchart}

\draw[/pgfgantt/canvas,fill=none]
    ([yshift=-0.5\pgflinewidth]canvas.north west) --
    (canvas.north west -| current bounding box.west) |-
    ([yshift=0.5\pgflinewidth]canvas.south west);

\end{tikzpicture}

\end{center}

\end{document}

I've found this in the pgf-gantt manual:

\newif\ifgtt@includetitle

\ganttset{%

include title in canvas/.is if=gtt@includetitle,%

include title in canvas

}

But I'm not sure how to work this into my code. Also, do you maybe have any tips for my chartt to look a bit fancier?

Thanks in advance!

Best, Lisa

0

1 Answer 1

2

The titles can be manually adjusted with the option title left skip. It takes a number, which is interpreted as a factor of a time slot width. It has to be given to all titles you want to extend.

Unfortunately, at the point the titles are set, the width of the description is not yet known. Therefore the value has to be set manually. If it is to low, the title bar doesn't reach all the way to the left. And caution, if it is to large, the width of the description will be expanded.

To ease the pain, I defined a macro \titleleftshift within the ganttchart environment and used it for the titles in question.

Here is the code:

\documentclass[a4paper, 11pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb} % amsmath loads amstext
\usepackage[english, ngerman]{babel}
\usepackage[hmargin=2.5cm,vmargin=2.5cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfgantt}

\begin{document}

\begin{center}

\begin{tikzpicture} % added

\begin{ganttchart}[%
    x unit=0.8cm,
    y unit title=0.8cm,
    y unit chart=0.6cm,
    vgrid,
    hgrid,
    bar/.append style={fill=MidnightBlue},
    milestone/.append style={fill=SkyBlue, rounded corners=3pt},
    bar label font=\footnotesize, % reduce font size
    milestone label font=\footnotesize\itshape, % reduce font size
    bar label node/.append style={align=right},
    milestone label node/.append style={align=right}, 
    canvas/.append style={name=canvas}
]{1}{12}
% set value here
\def\titleleftshift{-5.9}

% added title left shift option
\gantttitle[title left shift=\titleleftshift]{\textbf{YEAR 1}: Entry Phase}{12} \\
\gantttitlelist{1,...,12}{1} \\
\ganttbar{Literature: research and review}{1}{7} \\
\ganttbar{Writing of exposé}{4}{6} \\
\ganttmilestone{Public presentation}{7} \\
\ganttbar{Adaption of experiment 1}{11}{12} \\
\ganttbar{Conference participation\\\& networking}{11}{12} \\ % <- added a linebreak in the label text

\makeatletter
\advance\gtt@currentline by 1
\makeatother

% added title left shift option
\gantttitle[title left shift=\titleleftshift]{\textbf{YEAR 2}: Research Phase}{12} \\
\gantttitlelist{1,...,12}{1} \\

\makeatletter
\advance\gtt@currentline by -2
\makeatother

\ganttbar{Experiment 1: conduction}{1}{2} \\
\ganttbar{Planning of experiment 2}{3}{4} \\
\ganttbar{Organizing a workshop}{9}{11} \\
\ganttmilestone{Workshop}{11}

\end{ganttchart}

\draw[/pgfgantt/canvas,fill=none]
    ([yshift=-0.5\pgflinewidth]canvas.north west) --
    (canvas.north west -| current bounding box.west) |-
    ([yshift=0.5\pgflinewidth]canvas.south west);

\end{tikzpicture}

\end{center}

\end{document}

And the result:

enter image description here

You must log in to answer this question.

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