我正在用 构建甘特图pgfgantt
。
我对结果几乎很满意,但似乎不支持小数值。例如今天里程碑已设定,2018-12-15
但显示为 12 月底。测试里程碑已设定,2019-03-01
但显示在三月底。
有没有办法/解决方法将其放置在正确的 x 分数值处?
我在这个答案。
有没有办法用月份而不是数字来实现同样的效果?
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
vgrid,
hgrid,
x unit=2cm,
y unit chart=8mm,
milestone/.append style={xscale=0.2},
time slot format=isodate,
time slot unit=month
]{2018-12-01}{2019-06-30}
\gantttitlecalendar{year, month} \\
\ganttmilestone{Today}{2018-12-15} \\
\ganttbar{Task 1}{2019-01-01}{2019-01-31} \\
\ganttbar{Task 2}{2019-02-01}{2019-02-28} \ganttnewline
\ganttmilestone{Test}{2019-03-01}
\end{ganttchart}
\end{document}
我也尝试过使用time slot unit=day
,但是无法正确地将vgrid
线条与月份对齐。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
vgrid={*{29}{draw=none}, dotted}, % how to align with months?
hgrid,
x unit=0.8mm,
y unit chart=8mm,
milestone/.append style={xscale=5.5},
time slot format=isodate,
time slot unit=day
]{2018-12-01}{2019-06-30}
\gantttitlecalendar{year, month} \\
\ganttmilestone{Today}{2018-12-15} \\
\ganttbar{Task 1}{2019-01-01}{2019-01-31} \\
\ganttbar{Task 2}{2019-02-01}{2019-02-28} \ganttnewline
\ganttmilestone{Test}{2019-02-28}
\end{ganttchart}
\end{document}
答案1
这是一个提议,它附带一个fractional xshift
可以添加到选项中的新选项。如果您想要移动半个月(或者更一般地说,移动半个x unit
,则说fractional xshift=1/2
,如果您想移动一天,则使用fractional xshift=1/30
,依此类推。(我还删除了 MWE 中与问题不直接相关的部分。)
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[fractional xshift/.style={%
/tikz/xshift=#1*\pgfkeysvalueof{/pgfgantt/x unit},
milestone label node/.append style={xshift=-#1*\pgfkeysvalueof{/pgfgantt/x unit}}
},
vgrid,
hgrid,
x unit=2cm,
y unit chart=8mm,
milestone/.append style={xscale=0.2},
time slot format=isodate,
time slot unit=month
]{2018-12-01}{2019-06-30}
\gantttitlecalendar{year, month} \\
\ganttmilestone{Today}{2018-12-15} \\
\ganttbar{Task 1}{2019-01-01}{2019-01-31} \\
\ganttbar{Task 2}{2019-02-01}{2019-02-28} \ganttnewline
\ganttmilestone[fractional xshift=1/2]{Test}{2019-02-28}
\end{ganttchart}
\end{document}