# pgfgantt resolution; month for title, day for bars

I haven't yet come upon a good solution for representing tasks (bars) to daily resolution without having an overly busy gantt title i.e. limiting it at monthly resolution.

I would like to define start and end times for groups and tasks/bars with by a date specifier of the format: yyyy-mm-dd.

Here is an mwe:

\NeedsTeXFormat{LaTeX2e}
\documentclass[10pt]{standalone}
\usepackage{pgfgantt}
\usepackage[scaled]{helvet}

\newcommand{\graphstart}{2019-01}   % start of graph (two months buffer)
\newcommand{\graphend}{2019-09} % end date  (two months buffer)

\renewcommand\familydefault{\sfdefault}

% create a new command for a ganttbar entry
\newcommand{\ganttbarentry}[4]{%
\ganttbar[bar/.append style={pattern color = #1}]{#2}{#3}{#4}%
}%

\begin{document}
\begin{ganttchart}[
vgrid,
hgrid,
x unit=0.47cm,
y unit chart=0.41cm,
time slot format=isodate-yearmonth,
time slot unit=month,
%compress calendar=true,
bar/.append style={pattern=north west lines, pattern color = cyan},%
]{\graphstart}{\graphend}
\gantttitlecalendar{year, month}\\
%

\ganttgroup{Group I}{2019-03}{2019-05} \\%
% March 4th - 6th
\ganttbarentry{gray}{Task I}{2019-03}{2019-03} \\%
% March 15 - April 5th
\ganttbarentry{gray}{Task II}{2019-03}{2019-03} \\%
\\

\ganttgroup{Group II}{2019-03}{2019-05} \\%
% March 4th - 6th
\ganttbarentry{gray}{Task I}{2019-03}{2019-03} \\%
% March 4th - March 15th
\ganttbarentry{gray}{Task II}{2019-04}{2019-04} \\%

\end{ganttchart}
\end{document}


The output is blocky / limited to monthly resolution:

• You could "cheat": \ganttbar[ bar/.append style={xscale=1.5,xshift=1mm} ]{Task 2}{2019-03}{2019-03}. – user121799 Mar 4 '19 at 19:44
• @marmot, thanks for the interest. I think that yyyy-mm-dd formatted input is a strict requirement here. A workaround would be a function or macro which takes yyyy-mm-dd and computes either a relative week number or relative day number. The problem I'm trying to avoid is the manual translation of calendar dates to day or week number. – John Chris Mar 4 '19 at 22:00

## 1 Answer

Here is a proposal. It comes with a command \Ganttbarentry that works very similarly to your own command \ganttbarentry except that it takes six instead of four parameters. The last two parameters are the start and end days, so e.g.

\Ganttbarentry{gray}{Task I}{2019-03}{2019-03}{4}{6}


will give you a bar that stats at March 3 and ends at April 4.

\NeedsTeXFormat{LaTeX2e}
\documentclass[10pt]{standalone}
\usepackage{pgfgantt}
\usepackage[scaled]{helvet}

\newcommand{\graphstart}{2019-01}   % start of graph (two months buffer)
\newcommand{\graphend}{2019-09} % end date  (two months buffer)

\renewcommand\familydefault{\sfdefault}

% create a new command for a ganttbar entry
\newcommand{\ganttbarentry}[4]{%
\ganttbar[bar/.append style={pattern color = #1}]{#2}{#3}{#4}%
}%
\newcommand{\Ganttbarentry}[6]{%
\ganttbar[/pgfgantt/bar left shift=#5/30,
/pgfgantt/bar right shift=#6/30,bar/.append style={pattern color = #1}]{#2}{#3}{#4}%
}%

\begin{document}
\begin{ganttchart}[
vgrid,
hgrid,
x unit=0.47cm,
y unit chart=0.41cm,
time slot format=isodate-yearmonth,
time slot unit=month,
%compress calendar=true,
bar/.append style={pattern=north west lines, pattern color = cyan},%
]{\graphstart}{\graphend}
\gantttitlecalendar{year, month}\\
%

\ganttgroup{Group I}{2019-03}{2019-05} \\%
% March 4th - 6th
\Ganttbarentry{gray}{Task I}{2019-03}{2019-03}{4}{6} \\%
% March 15 - April 5th
\Ganttbarentry{gray}{Task II}{2019-03}{2019-03}{15}{5} \\%

\ganttgroup{Group II}{2019-03}{2019-05} \\%
% March 4th - 6th
\Ganttbarentry{gray}{Task I}{2019-03}{2019-03}{4}{6} \\%
% March 4th - March 15th
\Ganttbarentry{gray}{Task II}{2019-04}{2019-04}{4}{15} \\%

\end{ganttchart}
\end{document}


This may be improved in many ways. One way is to make it parse the full date (instead having the user have to split it up by hand). This appears doable, but more effort than one may naively expect. And the current version assumes that every month has 30 days. Implementing this appears doable, too, but even more tedious.