5

I want to create a simple pgfgantt-chart with a representation of calendarian weeks for a period of five months (october until february).

My challenge is: I could add the weeks via \gantttitlecalendar{year, month, week} easily, but: Depending on the long time span of five months, I will get 20 single (week) columns. Therefore the widths of the words "Week" are causing extremely wide column spaces, so the overall width of the whole chart is getting busted. You can assess this behaviour in the following image.


The result looks like that:

enter image description here

As you can see, it would be very nice to massively decrease the width of the "Week"-columns.


My current solution is working though, but is a pretty botch:

  • I created two separate pgfgantt-charts: One with the calendarian axis and one with a non-calendarian custom column axis and so called columns "W1, W2, W3, ... "W20" (which stands for "Week).
  • I aligned those two charts above each other via tabular-environment.

The result looks like that:

enter image description here

You can easily recognize the gap between the upper and the lower pgfgantt-chart. It is not bad, but also not a nice solution.


Now my dream would be a solution to also move the weekly columns into the first pgfgantt-chart without (!) busting the whole chart of it's original width. A possible solution could be to shrink the words "week" to "W1" or to vertically align the words in the columns.

How can I change that behaviour?

  • Option 1: Change the word "Week" to a short "W".
  • Option 2: Align the word "Week" vertically instead of horizontally.

Minimum Working Example (MWE)

\documentclass{standalone}
\usepackage{pgfgantt}

\begin{document}

\begin{tabular}{@{}r}

    \begin{ganttchart}[
        title/.append style={fill=black!10},
        x unit=4cm,
        compress calendar,
        time slot format=isodate-yearmonth,
    ]{2017-10}{2018-02}

    \gantttitlecalendar{year, month=name} \\
    \end{ganttchart}

\\

    \begin{ganttchart}[x unit=1cm]{1}{20}
        \gantttitle{W1}{1}
        \gantttitle{W2}{1}
        \gantttitle{W3}{1}
        \gantttitle{W4}{1}
        \gantttitle{W5}{1}
        \gantttitle{W6}{1}
        \gantttitle{W7}{1} 
        \gantttitle{W8}{1}
        \gantttitle{W9}{1}
        \gantttitle{W10}{1}
        \gantttitle{W11}{1}
        \gantttitle{W12}{1}
        \gantttitle{W13}{1}
        \gantttitle{W14}{1}
        \gantttitle{W15}{1}
        \gantttitle{W16}{1}
        \gantttitle{W17}{1}
        \gantttitle{W18}{1}
        \gantttitle{W19}{1}
        \gantttitle{W20}{1}\\

        \ganttbar{Task 1}{3}{6} \\
        \ganttbar{Task 2}{7}{10} \\
        \ganttbar{Task 3}{11}{14} \\
        \ganttbar{Task 3}{15}{18} \\
    \end{ganttchart}

\end{tabular}

\end{document}
1

I think is easier this way

\documentclass{article}
\usepackage{pgfgantt}


\begin{document}
    \ganttset{%
        calendar week text={%
            W\currentweek
        }%
    }


    \begin{ganttchart}[
        hgrid,
        vgrid,
        x unit=1mm,
        time slot format=isodate,
        time slot unit=day      
        ]{2020-02-10}{2020-06-25}
        \gantttitlecalendar{year, month=name, week=1} \\
        \ganttbar{}{2020-02-10}{2020-06-25}]
    \end{ganttchart}    
\end{document}
|improve this answer|||||
  • could you explain why? – naphaneal Dec 20 '19 at 20:44
3

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.

enter image description here

\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}

enter image description here

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.

|improve this answer|||||
  • Thank you very much for your great efforts Scott! I can see, you also had to mess around with some botches to make it more or less accurate. :-) The approach of your second idea looks very great indeed! Please have a look at my update above, it is almost perfect now. I just want to hide the ugly week no. 39 and it's done! :-) – Dave Nov 22 '17 at 4:25
2

Thanks to Scott Seidman, I played around without the compress command and got a further idea.

Here is another approach:

Another approach with year, month, week and day.


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:

Nearly 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}
|improve this answer|||||
  • 1
    I bet you can fix the ugly 39 simply by starting your calendar at the first Monday in October. – Scott Seidman Nov 22 '17 at 14:17
  • 1
    Also, note the method used is from tex.stackexchange.com/a/231091/111381 – Scott Seidman Nov 22 '17 at 14:18
  • "I bet you can fix the ugly 39 simply by starting your calendar at the first Monday in October." Yes, I tried that yesterday morning: Now it is looking fine with that (but still only a 99 % perfect solution instead of 100 %)... :-) In my current case it is okay. I also updated the link to the posting with the counter-solution directly. Thanks a lot for your help Scott! – Dave Nov 23 '17 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.