我还没有找到一个好的解决方案来将任务(条形图)表示为每日分辨率,而无需过于繁忙的甘特图标题,即将其限制为每月分辨率。
我想用以下格式的日期说明符来定义组和任务/栏的开始和结束时间:yyyy-mm-dd。
以下是一个 mwe:
\NeedsTeXFormat{LaTeX2e}
\documentclass[10pt]{standalone}
\usepackage{pgfgantt}
\usepackage[scaled]{helvet}
\newcommand{\graphstart}{2019-01} % start of graph (two months buffer)
\newcommand{\graphend}{2019-09} % end date (two months buffer)
\renewcommand\familydefault{\sfdefault}
% create a new command for a ganttbar entry
\newcommand{\ganttbarentry}[4]{%
\ganttbar[bar/.append style={pattern color = #1}]{#2}{#3}{#4}%
}%
\begin{document}
\begin{ganttchart}[
vgrid,
hgrid,
x unit=0.47cm,
y unit chart=0.41cm,
time slot format=isodate-yearmonth,
time slot unit=month,
%compress calendar=true,
bar/.append style={pattern=north west lines, pattern color = cyan},%
]{\graphstart}{\graphend}
\gantttitlecalendar{year, month}\\
%
\ganttgroup{Group I}{2019-03}{2019-05} \\%
% March 4th - 6th
\ganttbarentry{gray}{Task I}{2019-03}{2019-03} \\%
% March 15 - April 5th
\ganttbarentry{gray}{Task II}{2019-03}{2019-03} \\%
\\
\ganttgroup{Group II}{2019-03}{2019-05} \\%
% March 4th - 6th
\ganttbarentry{gray}{Task I}{2019-03}{2019-03} \\%
% March 4th - March 15th
\ganttbarentry{gray}{Task II}{2019-04}{2019-04} \\%
\end{ganttchart}
\end{document}
输出是块状的/仅限于每月的分辨率:
答案1
这是一项建议。它附带一个命令\Ganttbarentry
,其工作方式与您自己的命令非常相似,\ganttbarentry
只是它需要六个参数而不是四个参数。最后两个参数是开始和结束日期,因此例如
\Ganttbarentry{gray}{Task I}{2019-03}{2019-03}{4}{6}
将为您提供一个从 3 月 3 日开始到 4 月 4 日结束的条形图。
\NeedsTeXFormat{LaTeX2e}
\documentclass[10pt]{standalone}
\usepackage{pgfgantt}
\usepackage[scaled]{helvet}
\newcommand{\graphstart}{2019-01} % start of graph (two months buffer)
\newcommand{\graphend}{2019-09} % end date (two months buffer)
\renewcommand\familydefault{\sfdefault}
% create a new command for a ganttbar entry
\newcommand{\ganttbarentry}[4]{%
\ganttbar[bar/.append style={pattern color = #1}]{#2}{#3}{#4}%
}%
\newcommand{\Ganttbarentry}[6]{%
\ganttbar[/pgfgantt/bar left shift=#5/30,
/pgfgantt/bar right shift=#6/30,bar/.append style={pattern color = #1}]{#2}{#3}{#4}%
}%
\begin{document}
\begin{ganttchart}[
vgrid,
hgrid,
x unit=0.47cm,
y unit chart=0.41cm,
time slot format=isodate-yearmonth,
time slot unit=month,
%compress calendar=true,
bar/.append style={pattern=north west lines, pattern color = cyan},%
]{\graphstart}{\graphend}
\gantttitlecalendar{year, month}\\
%
\ganttgroup{Group I}{2019-03}{2019-05} \\%
% March 4th - 6th
\Ganttbarentry{gray}{Task I}{2019-03}{2019-03}{4}{6} \\%
% March 15 - April 5th
\Ganttbarentry{gray}{Task II}{2019-03}{2019-03}{15}{5} \\%
\ganttgroup{Group II}{2019-03}{2019-05} \\%
% March 4th - 6th
\Ganttbarentry{gray}{Task I}{2019-03}{2019-03}{4}{6} \\%
% March 4th - March 15th
\Ganttbarentry{gray}{Task II}{2019-04}{2019-04}{4}{15} \\%
\end{ganttchart}
\end{document}
可以通过多种方式改进这一点。一种方法是让它解析完整日期(而不是让用户手动拆分)。这看起来可行,但需要付出的努力可能比人们天真的预期要多。而且当前版本假设每个月有 30 天。实现这一点看起来也是可行的,但更加繁琐。