开放式甘特图

开放式甘特图

有没有办法pgfgantt制作gantt带有开放行的图表,或者我知道如何用 LaTeX 实现这一点?

到目前为止,我有下面的代码,它产生如图 1 所示的输出。

在此处输入图片描述

\vspace{-0cm}
\begin{figure}[H]
\centering
\begin{ganttchart}[
    x unit=0.35cm,
    y unit chart=0.7cm,
    canvas/.style={draw=none,fill=none}, % remove canvas borders, etc
    vgrid={*1{draw=black!12}},           % vertical gray lines every unit
    inline,                              % draw bars inline
    group/.style={draw=none,fill=none},  % remove group borders, etc
    bar top shift=0.125,                   % give bar 10% padding top/bottom
    bar height=0.8,                      % bar size 80% of vertical space
    y unit title=0.5cm,                  % crop titles a little smaller
    title/.style={draw=none,fill=none},  % remove title borders, etc
    include title in canvas=false        % no vertical grid in title
]{-1}{20}

\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}  
\gantttitle{}{2} 
\gantttitle{}{2}
\gantttitle{}{2}\\

\ganttgroup[inline=false]{$S$}{0}{1}
\ganttbar[bar/.style={draw}]{$\cdots$}{0}{4}
\ganttbar[bar/.style={draw}]{$i$}{5}{7}
\ganttbar[bar/.style={fill = green, draw}]{}{8}{9}
\ganttbar[bar/.style={draw}]{$j$}{10}{13} 
\ganttbar[bar/.style={draw}]{$\cdots$}{14}{18}\\ \\

\ganttgroup[inline=false]{$S^{'}$}{0}{1}
\ganttbar[bar/.style={draw}]{$\cdots$}{1}{5}
\ganttbar[bar/.style={draw}]{$i$}{6}{8}
\ganttbar[bar/.style={fill = green, draw}]{}{9}{9}
\ganttbar[bar/.style={draw}]{$j$}{10}{13} 
\ganttbar[bar/.style={draw}]{$\cdots$}{14}{18}
\end{ganttchart}
\captionsetup{format=hang, justification =centering}
\caption{}
\label{Figq4}
\end{figure}
  • 我怎样才能在行之间写一些内容?
  • 是否可以将行变为开放的?

我在下图中展示了我想要做的事情的一个示例。谢谢你的帮助。

在此处输入图片描述

答案1

为了实现这一点,您需要定义新的形状。幸运的是,几乎所有东西都可以从形状 继承ganttbar。只有\backgroundpath(绘制的边框)必须重新定义。然后,您可以将新形状与 一起使用 \ganttbar[bar/.style={shape=...

\documentclass{standalone}
\usepackage{pgfgantt}

\makeatletter
\pgfdeclareshape{ganttbaropenleft}{
  \inheritsavedanchors[from=ganttbar]
  \inheritanchor[from=ganttbar]{center}
  \inheritanchor[from=ganttbar]{mid}
  \inheritanchor[from=ganttbar]{base}
  \inheritanchor[from=ganttbar]{north}
  \inheritanchor[from=ganttbar]{south}
  \inheritanchor[from=ganttbar]{west}
  \inheritanchor[from=ganttbar]{mid west}
  \inheritanchor[from=ganttbar]{base west}
  \inheritanchor[from=ganttbar]{north west}
  \inheritanchor[from=ganttbar]{south west}
  \inheritanchor[from=ganttbar]{east}
  \inheritanchor[from=ganttbar]{mid east}
  \inheritanchor[from=ganttbar]{base east}
  \inheritanchor[from=ganttbar]{north east}
  \inheritanchor[from=ganttbar]{south east}
  \inheritanchorborder[from=ganttbar]
  \inheritanchor[from=ganttbar]{on top}
  \inheritanchor[from=ganttbar]{on bottom}
  \inheritanchor[from=ganttbar]{on left}
  \inheritanchor[from=ganttbar]{on right}

  \backgroundpath{
    \pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}
    \pgfgetlastxy{\gb@sw@x}{\gb@sw@y}
    \pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgfgetlastxy{\gb@ne@x}{\gb@ne@y}
    \pgfpathmoveto{\pgfpoint{\gb@sw@x}{\gb@sw@y}}
    \pgfpathlineto{\pgfpoint{\gb@ne@x}{\gb@sw@y}}
    \pgfpathlineto{\pgfpoint{\gb@ne@x}{\gb@ne@y}}
    \pgfpathlineto{\pgfpoint{\gb@sw@x}{\gb@ne@y}}
  }
}

\pgfdeclareshape{ganttbaropenright}{
  \inheritsavedanchors[from=ganttbar]
  \inheritanchor[from=ganttbar]{center}
  \inheritanchor[from=ganttbar]{mid}
  \inheritanchor[from=ganttbar]{base}
  \inheritanchor[from=ganttbar]{north}
  \inheritanchor[from=ganttbar]{south}
  \inheritanchor[from=ganttbar]{west}
  \inheritanchor[from=ganttbar]{mid west}
  \inheritanchor[from=ganttbar]{base west}
  \inheritanchor[from=ganttbar]{north west}
  \inheritanchor[from=ganttbar]{south west}
  \inheritanchor[from=ganttbar]{east}
  \inheritanchor[from=ganttbar]{mid east}
  \inheritanchor[from=ganttbar]{base east}
  \inheritanchor[from=ganttbar]{north east}
  \inheritanchor[from=ganttbar]{south east}
  \inheritanchorborder[from=ganttbar]
  \inheritanchor[from=ganttbar]{on top}
  \inheritanchor[from=ganttbar]{on bottom}
  \inheritanchor[from=ganttbar]{on left}
  \inheritanchor[from=ganttbar]{on right}

  \backgroundpath{
    \pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}
    \pgfgetlastxy{\gb@sw@x}{\gb@sw@y}
    \pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgfgetlastxy{\gb@ne@x}{\gb@ne@y}
    \pgfpathmoveto{\pgfpoint{\gb@ne@x}{\gb@sw@y}}
    \pgfpathlineto{\pgfpoint{\gb@sw@x}{\gb@sw@y}}
    \pgfpathlineto{\pgfpoint{\gb@sw@x}{\gb@ne@y}}
    \pgfpathlineto{\pgfpoint{\gb@ne@x}{\gb@ne@y}}
  }
}
\makeatother


\begin{document}
\begin{ganttchart}[
    x unit=0.35cm,
    y unit chart=0.7cm,
    canvas/.style={draw=none,fill=none}, % remove canvas borders, etc
    vgrid={*1{draw=black!12}},           % vertical gray lines every unit
    inline,                              % draw bars inline
    group/.style={draw=none,fill=none},  % remove group borders, etc
    bar top shift=0.125,                   % give bar 10% padding top/bottom
    bar height=0.8,                      % bar size 80% of vertical space
    y unit title=0.5cm,                  % crop titles a little smaller
    title/.style={draw=none,fill=none},  % remove title borders, etc
    include title in canvas=false        % no vertical grid in title
]{-1}{20}

\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}
\gantttitle{}{2}  
\gantttitle{}{2} 
\gantttitle{}{2}
\gantttitle{}{2}\\

\ganttgroup[inline=false]{$S$}{0}{1}
\ganttbar[bar/.style={shape=ganttbaropenleft,draw}]{$\cdots$}{0}{4}
\ganttbar[bar/.style={draw}]{$i$}{5}{7}
\ganttbar[bar/.style={fill = green, draw}]{}{8}{9}
\ganttbar[bar/.style={draw}]{$j$}{10}{13} 
\ganttbar[bar/.style={shape=ganttbaropenright,draw}]{$\cdots$}{14}{18}\\ \\

\ganttgroup[inline=false]{$S^{'}$}{0}{1}
\ganttbar[bar/.style={shape=ganttbaropenleft,draw}]{$\cdots$}{1}{5}
\ganttbar[bar/.style={draw}]{$i$}{6}{8}
\ganttbar[bar/.style={fill = green, draw}]{}{9}{9}
\ganttbar[bar/.style={draw}]{$j$}{10}{13} 
\ganttbar[bar/.style={shape=ganttbaropenright,draw}]{$\cdots$}{14}{18}
\end{ganttchart}
\end{document}

在此处输入图片描述

相关内容