8

I am using ganttchart to make a time plan for my master thesis but when I set the calendar week text to \currentweek it does not "reset" on new year but just keeps going. The fist week number is correct but in January I have week 54 instead of 2.

How can i solve this?

Kajsa
  • 677

1 Answers1

7

I have solved the problem using a new command. Probably not the optimal solution but I added a new counter and command and set the week text to show the counter value.

%%% Preamble
\documentclass[paper=a4, fontsize=11pt]{scrartcl}   % Article class of KOMA-script with 11pt font and a4 format
\usepackage[pdftex]{graphicx}   %Enable pdflatex
\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}{49}
\ganttset{%
calendar week text={\myWeek{}}%
}
%
\begin{figure}[h!bt]
\begin{center}
\begin{ganttchart}[
vgrid={*{6}{draw=none}, dotted},
x unit=.08cm,
y unit title=.6cm,
y unit chart=.6cm,
time slot format=isodate,
time slot format/start date=2014-12-01]{2014-12-01}{2015-04-30}
\ganttset{bar height=.6}
\gantttitlecalendar{year, month=name, week} \\
\ganttbar[bar/.append style={fill=blue}]{Task 1}{2014-12-01}{2015-01-19}\\
\ganttbar[bar/.append style={fill=red}]{Task 2}{2015-03-10}{2015-04-19}
\end{ganttchart}
\end{center}
\caption{Time Plan}
\end{figure}
\end{document}

This gives me the correct week numbers.Time plan

Paul Gessler
  • 29,607
Kajsa
  • 677
  • This is great and it helped me a lot. But please note, that your start date must always correspond to a Monday. Otherwise, the spacing of the dotted lines does not correspond to the vertical lines of the "week boxes". Would you know how to "fix" that? ... That would be helpful to me, since I have to split my chart into multiple rows (too long) and I have to do that exactly in half year intervals. – Raphael Jun 02 '15 at 22:54
  • @Raphael I do not know how to make it automatic but the code that makes the dotted lines is vgrid={*{6}{draw=none}, dotted}. If your chart starts on a e.g. tuesday, changing this line to vgrid={*{5}{draw=none}, dotted, draw=none} should work. – Kajsa Jun 04 '15 at 06:35
  • Thanks for the help, but this seems to help ONLY for the first week. All other "week-lines" are off if I am using this code. – Raphael Jun 09 '15 at 23:03
  • @Kajsa: Thanks a lot for your work! Do you have any ideas on how to count the week numbers according to ISO 8601 standard scheme? https://tex.stackexchange.com/q/510434/78784 – Dave Oct 03 '19 at 20:23