pgfgantt:从周日开始一周吗?

pgfgantt:从周日开始一周吗?

我希望我的甘特图显示从周日开始的一周。您可以在 MWE 中的第二张甘特图中看到这一点。我该如何实现这一点而不明确写出每一周?

我的用例是项目管理,工作周从周日开始。

最小工作示例

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

理想的解决方案是有一个选项可以将星期几从星期一改为星期日。但我认为这是硬编码的。我检查了 TiZ 手册的相关章节(89.1.3 排版日期)并没有找到任何对我有帮助的东西。

唯一提到类似话题的另一个问题是Tikz 日历,一周从周日开始但它没有帮助,因为它没有修改一周的开始时间并且没有使用pgfgantt

答案1

开始日期确实是硬编码的,但更改起来并不太难。代码的原始calendar/week/.code 用途Sunday是部分\ifdate{}代码。我们只需将其更改为Saturday让星期从星期日开始。我不知道软件包作者是否愿意接受功能请求,但这是一个非常简单的添加,可以允许不同的开始日期。

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

代码输出

相关内容