考虑以下最小工作示例(MWE):
\documentclass{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart} [ time slot format = isodate,
vgrid = { *{6}{dotted}, *{1}{dashed} }
]
{2019-01-01}{2019-02-28}
\gantttitlecalendar{year, month=shortname}\\
\end{ganttchart}
\end{document}
结果截图:
如你看到的:
dotted
星期一至星期六的星期几以线型显示dashed
星期日以线型显示
问题:
新年期间,星期几不一定从星期一开始。如何将星期几名称设置为“真实”的星期几?
例如,2019 年 1 月 1 日是星期二,而不是星期一。如何改变这种行为?
答案1
这主要是为了告诉你问题出在哪里(在我看来)。我试图“破解”样式vgrid
。问题是,当执行此代码时,根据我发现的情况,开始和结束日期是未知的。如果是,可以破解它。因此,暂时,我添加了一些可以在图表中添加的代码,即当这些日期“已知”时。当然有很多未解决的问题,首先是\y@mid
数量不合适。尽管如此,此代码确实绘制了一个垂直网格,其中将工作日与周六和周日区分开来。它们每个都以相同名称的样式绘制。
\documentclass{standalone}
\usepackage{pgfgantt}
\tikzset{workday/.style={dashed},Saturday/.style={blue},Sunday/.style={red},
all days/.style={shorten <=2.5pt}}
\makeatletter
\newcount\pgf@currday
\ganttset{ivgrid/.code={\typeout{start=\the\gtt@startjulian,end=\the\gtt@endjulian}
\begin{scope}%[on background layer]%
\ifgtt@includetitle%
\def\y@upper{0}%
\else%
\pgfmathsetmacro\y@upper{%
\gtt@lasttitleline * \ganttvalueof{y unit title}%
}%
\fi%
\pgfmathsetmacro\y@lower{%
\gtt@lasttitleline * \ganttvalueof{y unit title}%
+ (\gtt@currentline - \gtt@lasttitleline - 1)%
* \ganttvalueof{y unit chart}%
}%
\pgfmathsetmacro\y@mid{%
(\y@upper + \y@lower) / 2%
}%
\pgfmathsetmacro\y@size{%
abs(\y@lower - \y@upper)%
}%
\edef\idiff{\the\numexpr\gtt@endjulian-\gtt@startjulian}
\pgf@currday=\gtt@startjulian%
\gtt@currgrid=0%
\loop%
\pgfcalendarjuliantodate{\pgf@currday}{\myyear}{\mymonth}{\myday}%
\pgfcalendarifdate{\myyear-\mymonth-\myday}{workday}{%
\draw [all days,workday]
(\gtt@currgrid * \ganttvalueof{x unit}, \y@mid pt) --%
(\gtt@currgrid * \ganttvalueof{x unit}, \y@lower pt);
}{\pgfcalendarifdate{\myyear-\mymonth-\myday}{Saturday}{%
\draw [all days,Saturday]
(\gtt@currgrid * \ganttvalueof{x unit}, \y@mid pt) --%
(\gtt@currgrid * \ganttvalueof{x unit}, \y@lower pt);
}{%
\draw [all days,Sunday]
(\gtt@currgrid * \ganttvalueof{x unit}, \y@mid pt) --%
(\gtt@currgrid * \ganttvalueof{x unit}, \y@lower pt);
}}
\advance\pgf@currday by1\relax%
\advance\gtt@currgrid by1\relax%
\unless\ifnum\the\pgf@currday>\the\gtt@endjulian\repeat%
\end{scope}
}}
\makeatother
\begin{document}
\begin{ganttchart}[time slot format=isodate]{2019-01-01}{2019-02-28}
\gantttitlecalendar{year, month=shortname}\\
\ganttset{ivgrid}
\end{ganttchart}
\end{document}