甘特图分为两部分,位于同一条线上

甘特图分为两部分,位于同一条线上

我想设计一个由两个连续阶段组成的工作包。因此,我会在同一条线上画两个矩形。

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

结果:

在此处输入图片描述

相关内容