pgfgantt: How to customize "week"-columns in a gantt chart (or other ideas)?
Your problem is with "compress". If you don't use it, you have much more freedom to use time units smaller than 1 month. Another problem is that a month is not 4 weeks. Here's a bodge using the "simple" time slot format, 28-day months and 7-day weeks.
\documentclass{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
title/.append style={fill=black!10},
x unit=3pt,
%compress calendar,
time slot format=simple,
]{1}{140}
\gantttitle{2017}{84}
\gantttitle{2018}{56} \\
\gantttitle{October}{28}
\gantttitle{November}{28}
\gantttitle{December}{28}
\gantttitle{January}{28}
\gantttitle{February}{28}\\
\gantttitle{W1}{7}
\gantttitle{W2}{7}
\gantttitle{W3}{7}
\gantttitle{W4}{7}
\gantttitle{W5}{7}
\gantttitle{W6}{7}
\gantttitle{W7}{7}
\gantttitle{W8}{7}
\gantttitle{W9}{7}
\gantttitle{W10}{7}
\gantttitle{W11}{7}
\gantttitle{W12}{7}
\gantttitle{W13}{7}
\gantttitle{W14}{7}
\gantttitle{W15}{7}
\gantttitle{W16}{7}
\gantttitle{W17}{7}
\gantttitle{W18}{7}
\gantttitle{W19}{7}
\gantttitle{W20}{7}\\
\ganttbar{Task 1}{3}{6} \\
\ganttbar{Task 2}{7}{10} \\
\ganttbar{Task 3}{11}{14} \\
\ganttbar{Task 3}{15}{18} \\
\end{ganttchart}
\end{document}
Alternatively, you can go with real dates, and 7-day weeks, but the weeks won't line up with the months
\documentclass{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
title/.append style={fill=black!10},
x unit=3pt,
time slot format=isodate,
]{2017-10-1}{2018-02-28}
\gantttitlecalendar{year, month=name} \\
\gantttitle{W1}{7}
\gantttitle{W2}{7}
\gantttitle{W3}{7}
\gantttitle{W4}{7}
\gantttitle{W5}{7}
\gantttitle{W6}{7}
\gantttitle{W7}{7}
\gantttitle{W8}{7}
\gantttitle{W9}{7}
\gantttitle{W10}{7}
\gantttitle{W11}{7}
\gantttitle{W12}{7}
\gantttitle{W13}{7}
\gantttitle{W14}{7}
\gantttitle{W15}{7}
\gantttitle{W16}{7}
\gantttitle{W17}{7}
\gantttitle{W18}{7}
\gantttitle{W19}{7}
\gantttitle{W20}{7}
\gantttitle{W21}{7}\\
\ganttbar{Task 1}{2017-10-15}{2017-10-30} \\
\end{ganttchart}
\end{document}
I tried pretty hard to fake things using fractional units for the week titles to make them roughly 4 weeks per month, but had a hard time with that.
Thanks to Scott Seidman, I played around without the compress
command and got a further idea.
Here is another approach:
As you can see, I removed the compress
command and got the ability to customize the chart size more easy. If I set the title font sizes to tiny
(via title label font=\tiny
), the result is nearly usable.
When I changed the behaviour of the "Week" appearance successfully, I will delete the day
-timeline. This timeline is just there to compare the suiting week numbers.
Only two useful features are still missing now:
- How to change the "Week"-titles to vertical text direction instead of (classic) horizontal text direction? This could free a lot of width space which is actually occupied by the word "Week". The
rotating
-package won't help I guess? - How to change the counting of the weeks to real calendarian week numbers instead of initial numbers (which start counting from the first displayed month)? The first day of october should be in calendarian week no. 39 while the last day of februar (02/28/2018) should be in calendarian week no. 9. Update: Solution found!
Minimum Working Example (MWE):
\documentclass{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
title/.append style={fill=black!10},
title label font=\tiny,
x unit=7pt,
time slot format=isodate,
]{2017-10-01}{2018-02-28}
\gantttitlecalendar{year, month=name, week, day} \\
\ganttbar{Task 1}{2017-10-01}{2017-12-01} \\
\ganttbar{Task 1}{2017-11-01}{2018-02-01} \\
\end{ganttchart}
\end{document}
Update:
I found solutions to change the displayed name of the week as well as to reset the counter at new year!
Now it looks like the following image and is almost perfect:
The last thing is: How can I avoid the ugly display of week no. 39?
Minimum Working Example (MWE):
\documentclass{standalone}
\usepackage{pgfgantt}
\newcounter{myWeekNum}
\stepcounter{myWeekNum}
%
\newcommand{\myWeek}{\themyWeekNum
\stepcounter{myWeekNum}
\ifnum\themyWeekNum=53
\setcounter{myWeekNum}{1}
\else\fi
}
%
%%% Begin document
\begin{document}
\setcounter{myWeekNum}{39}
\ganttset{%
calendar week text={\myWeek{}}%
}
\begin{ganttchart}[
title/.append style={fill=black!10},
title label font=\tiny,
x unit=4pt,
time slot format=isodate,
]{2017-10-01}{2018-02-28}
\ganttset{calendar week text={\myWeek{}}}
\gantttitlecalendar{year, month=name, week=39 day,day}\\
\ganttbar{Task 1}{2017-10-01}{2017-12-01} \\
\ganttbar{Task 1}{2017-11-01}{2018-02-01} \\
\end{ganttchart}
\end{document}