2

Is there a way to use pgfgantt to make the gantt chart with open ended rows, or any idea how can I accomplish this in LaTeX?

So far I have the code below which produces the output as in Figure 1.

enter image description here

\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}
  • How can I write something in-between the rows?
  • Is it possible to make the rows open ended?

I have shown an example of what I wish to do in the figure below. Thanks for the help.

enter image description here

2
  • Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. Commented Apr 18, 2018 at 12:49
  • sure I can do that, I am here new thanks for the heads up.
    – Inemzireno
    Commented Apr 18, 2018 at 12:55

1 Answer 1

3

To achieve this, you need to define new shapes. Luckily, nearly everything can be inherited from the shape ganttbar. Only the \backgroundpath (the drawn border) must be redefined. Then you can use the new shapes with \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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .