5

I want my Gantt chart to display with the week starting on Sunday. You can see this in the second gantt chart in the MWE. How do I accomplish that without explicitly writing out each week?

My use case is for project management and the work week starts on Sunday.

Minimum Working Example

\documentclass[a4paper]{article}
\usepackage{pgfgantt}

\begin{document}

\begin{ganttchart}[
  hgrid,
  vgrid,
  x unit = 1cm,
  time slot format=isodate
  ]{2022-06-19}{2022-07-01}
  \gantttitlecalendar{year, month, week, day, weekday=shortname} \\
\end{ganttchart}

\begin{ganttchart}[
  hgrid,
  vgrid,
  x unit = 1cm,
  time slot format=isodate
  ]{2022-06-19}{2022-07-01}
  \gantttitlecalendar{year, month} \\
  \gantttitle{Week 1}{7}
  \gantttitle{Week 2}{6} \\
  \gantttitlecalendar{day, weekday=shortname} \\
\end{ganttchart}

\end{document}

The ideal solution would be to have an option to switch the week day start from meaning Monday to Sunday. But I think that's hard coded. I have checked the TikZ manual's relevant sections (89.1.3 Typesetting Dates) and didn't find anything that helps me.

The only other question that mentions a similar topic is Tikz calendar with week starting on Sunday but it was unhelpful because it didn't modify when the week started and does not use pgfgantt.

New contributor
adham327 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • 1
    Welcome to TeX.se and thanks for adding a minimal example document to your question!
    – Alan Munn
    Jun 21 at 12:43

1 Answer 1

4

The start day is indeed hard coded but it's not too difficult to change. The original calendar/week/.code uses Sunday in the \ifdate{} part of the code. We simply need to change this to Saturday to have weeks begin on Sunday. I don't know if the package author would be open to feature requests, but this would be a very simple addition to make to allow a different start day.

\documentclass[a4paper]{article}
\usepackage{pgfgantt}
\makeatletter
\ganttset{
  calendar/week/.code={%
    \ifgtt@calendar@eol\ganttnewline\fi%
    \begingroup%
    \gtt@calendar@slots=1\relax%
    \gtt@calendar@weeknumber=#1\relax%
    \pgfcalendar{}{\gtt@calendar@startdate}{\gtt@calendar@enddate}{%
      \ifdate{Saturday}{%
        \gtt@calendar@startofweek=\pgfcalendarcurrentjulian\relax%
        \advance\gtt@calendar@startofweek by1\relax%
        \advance\gtt@calendar@startofweek by-\gtt@calendar@slots\relax%
        \pgfcalendarjuliantodate{\gtt@calendar@startofweek}%
          {\startyear}{\startmonth}{\startday}%
        \def\currentweek{\the\gtt@calendar@weeknumber}%
        \gantttitle{%
          \ganttvalueof{calendar week text}%
        }{%
          \the\gtt@calendar@slots%
        }%
        \gtt@calendar@slots=1\relax%
        \advance\gtt@calendar@weeknumber by1\relax%
      }{%
        \advance\gtt@calendar@slots by1%
      }%
      \ifdate{equals=\pgfcalendarendiso}{%
        \ifnum\gtt@calendar@slots=1\relax\else%
          \advance\gtt@calendar@slots by-1\relax%
          \gtt@calendar@startofweek=\pgfcalendarcurrentjulian\relax%
          \advance\gtt@calendar@startofweek by1\relax%
          \advance\gtt@calendar@startofweek by-\gtt@calendar@slots\relax%
          \pgfcalendarjuliantodate{\gtt@calendar@startofweek}%
            {\startyear}{\startmonth}{\startday}%
          \def\currentweek{\the\gtt@calendar@weeknumber}%
          \gantttitle{%
            \ganttvalueof{calendar week text}%
          }{%
            \the\gtt@calendar@slots%
          }%
        \fi%
      }{}%
    }%
    \endgroup%
    \gtt@calendar@eoltrue%
  }
}
\makeatother
\begin{document}

\begin{ganttchart}[
  hgrid,
  vgrid,
  x unit = 1cm,
  time slot format=isodate
  ]{2022-06-19}{2022-07-01}
  \gantttitlecalendar{year, month, week, day, weekday=shortname} \\
\end{ganttchart}

\end{document}

output of code

Your Answer

adham327 is a new contributor. Be nice, and check out our Code of Conduct.

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.