![甘特图分为两部分,位于同一条线上](https://linux22.com/image/473072/%E7%94%98%E7%89%B9%E5%9B%BE%E5%88%86%E4%B8%BA%E4%B8%A4%E9%83%A8%E5%88%86%EF%BC%8C%E4%BD%8D%E4%BA%8E%E5%90%8C%E4%B8%80%E6%9D%A1%E7%BA%BF%E4%B8%8A.png)
我想设计一个由两个连续阶段组成的工作包。因此,我会在同一条线上画两个矩形。
\documentclass{article}
\RequirePackage{pgfgantt}
\begin{document}
\begin{ganttchart}[time slot format=isodate-yearmonth,
vgrid={dotted,draw=none,draw=none},
x unit=0.22cm,
y unit chart = 0.6cm, bar height=0.6,
y unit title = 0.5cm, title height=1,
time slot unit=month
]{2024-09}{2029-09} %project duration
\gantttitlecalendar[title/.style={fill=black!30,draw=black}]{year} \\
\ganttbar{WP0}{2024-09}{2029-09} \\
\end{ganttchart}
\end{document}
答案1
默认情况下,pgfgantt
条形图会打印在同一行上,除非您以 结束该行\\
。因此:
% the following bars are on the same line:
\ganttbar{label}{from}{to}
\ganttbar{label}{from}{to}
相对:
% the following bars are on different lines:
\ganttbar{label}{from}{to}\\
\ganttbar{label}{from}{to}
为了使图表更清晰,您可以内联标签:
\ganttbar[inline]{WP0a}{2024-09}{2027-05}
\ganttbar[inline]{WP0b}{2027-06}{2029-09}\\
要在图表外面加上标签,您可以添加任意长度的虚拟条,例如全长,仅用于打印标签:
\ganttbar{WP0}{2024-09}{2029-09}
完整代码:
\documentclass{article}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[time slot format=isodate-yearmonth,
vgrid={dotted,draw=none,draw=none},
x unit=0.22cm,
y unit chart = 0.6cm, bar height=0.6,
y unit title = 0.5cm, title height=1,
time slot unit=month
]{2024-09}{2029-09} %project duration
\gantttitlecalendar[title/.style={fill=black!30,draw=black}]{year} \\
\ganttbar{WP0}{2024-09}{2029-09}
\ganttbar[inline]{WP0a}{2024-09}{2027-05}
\ganttbar[inline]{WP0b}{2027-06}{2029-09}\\
\ganttbar{WP1}{2026-01}{2027-01}
\end{ganttchart}
\end{document}
结果: