1

I am using the following code but I want to incorporate some dashes as in the picture.

\documentclass[a4paper, 12pt,fleqn]{article} 
\usepackage{pgfgantt}
\begin{document}
\begin{figure}
\centering
{\sffamily
\begin{ganttchart}[%
  inline, 
  y unit title=1.1cm,
  canvas/.style={draw=none},
  title/.style={draw=none},
  bar inline label anchor=west,
  bar inline label node/.append style={anchor=west, text=white},
  bar/.append style={fill=cyan!90!black,}, 
  bar height=.8,]{0}{18}
  \ganttbar[inline=false]{M1}{0}{3}
  \ganttbar{J1}{0}{3}
  \ganttbar{J2}{3}{4}
  \ganttbar{}{5}{18}\\
  \ganttbar[inline=false]{M2}{0}{5}
  \ganttbar{J2}{5}{8}
  \ganttbar{J1}{8}{12}
  \ganttbar{}{12}{18}\\
  \gantttitlelist{0,...,18}{1}
\end{ganttchart}
}
\caption{To demonstrate Flow shop Scheduling}
\end{figure}
\end{document}

Is there a way to rebuild my Gantt chart to get this look

?is that possible

I just want to have a line with t and dashes. The rest should be similar to the output of the code above.

3
  • What was your last code, you posted? It'll be much easier for us, if you gave the link yourself.
    – Jan
    Commented Dec 23, 2016 at 11:51
  • 1
    @jan the last code is there ?
    – Milo Li
    Commented Dec 23, 2016 at 12:20
  • 2
    I interpreted the term "the last code I posted" to be another question, you placed on TeX.SE. At least to me your term is ambiguous.
    – Jan
    Commented Dec 23, 2016 at 17:06

2 Answers 2

6

Here is a possibility, though it's a bit of a hack.

First, add a tikzpicture environment around the pgfgantt environment. This is used to be able to draw some additional stuff.

In the \gantttitlelist, add [title label node/.append style={alias=n\x,opacity=0}]. \x is the number, so the node with number 1 will be given the alias n1, and so on. With zero opacity the numbers are invisible.

I think the nodes in the title list are placed equidistant, but because they have different widths, it isn't accurate to use their corners as references. So what I do is to calculate the horizontal distance between the centers of two of the nodes (n0 and n1), and then draw the tick this distance to the left of the north anchor of the nodes. This appears to be accurate.

enter image description here

\documentclass[a4paper, 12pt,fleqn]{article} 
\usepackage{pgfgantt}
\usetikzlibrary{calc}
\begin{document}
\begin{figure}
\centering
\sffamily
\begin{tikzpicture}
\begin{ganttchart}[%
   inline, 
   y unit title=1.1cm,
   canvas/.style={draw=none},
   title/.style={draw=none},
   bar inline label anchor=west,
   bar inline label node/.append style={anchor=west, text=white},
   bar/.append style={fill=cyan!90!black,}, 
   bar height=.8,]{0}{18}
\ganttbar[inline=false]{M1}{0}{3}
\ganttbar{J1}{0}{3}
\ganttbar{J2}{3}{4}
\ganttbar{}{5}{18}\\
\ganttbar[inline=false]{M2}{0}{5}
\ganttbar{J2}{5}{8}
\ganttbar{J1}{8}{12}
\ganttbar{}{12}{18}\\
\gantttitlelist[title label node/.append style={alias=n\x,opacity=0}]{0,...,18}{1}
\end{ganttchart}
\draw [-latex] (n0.north west) -- ([xshift=7pt]n18.north east) node[right] {$t$};
\foreach \N in {0,...,18} {
  \draw
   let
   \p1=(n0.center), \p2=(n1.center),\n1={(\x2-\x1)/2}
   in
  (n\N.north) +(-\n1,2pt) -- +(-\n1,-2pt) node[below,font=\small]{\N};
}

% draw tick for 19
\draw
   let
   \p1=(n0.center), \p2=(n1.center),\n1={(\x2-\x1)/2}
   in
  (n18.north) +(\n1,2pt) -- +(\n1,-2pt) node[below,font=\small]{19};

\end{tikzpicture}
\caption{To demonstrate Flow shop Scheduling}
\end{figure}
\end{document}
10
  • it doesent work with \draw latex....
    – Milo Li
    Commented Dec 30, 2016 at 19:59
  • @MiloLi What doesn't work with what, and how does it not work? You need to be more precise. Commented Dec 30, 2016 at 20:14
  • it works, but with this solution i have the problem that the dash between 12 and 13 on M1 is wrong. The dash must be exactly over 12! Do you know what i mean ?
    – Milo Li
    Commented Dec 30, 2016 at 20:24
  • and the numbers on the axis look weird. It seems that they dont have the right distance. Some space is bigger some is shorter...
    – Milo Li
    Commented Dec 30, 2016 at 20:33
  • @MiloLi Yes, that is a problem that I didn't notice when I first posted the answer, but I did mention it in an edit (read the paragraph starting with "Note that ..."). I didn't find a good workaround yesterday, but I can try again. Commented Dec 30, 2016 at 20:50
3

After finally understanding whet the OP wants, here is a possible solution, using the pst-plot package:

\documentclass{article}

\usepackage{geometry} % avoid `overfull \hbox' warning
\usepackage{pst-plot}

\psset{
  xunit = 0.6,
  dimen = m
}

\def\Gantt(#1,#2)[#3]#4{%
  \psframe[fillstyle = solid, fillcolor = cyan]%
    (!#1 #2 0.8 sub)(!#1 #3 add #2 0.1 sub)
  \uput[0](!#1 #2 0.45 sub){\textcolor{white}{$\mathrm{#4}$}}}

% marco syntax:
% \Gantt(<t-start>,<stack number, vertical>){<t-lengte>}[<label>]


\begin{document}

\begin{center}
\begin{pspicture}(-0.9,-0.52)(19.78,2.5) % boundry found manually
  \psline(0,0)(0,2.5)
  \psaxes[yAxis = false]{->}(0,0)(19.35,0)[$t$,0][,90]
  \multido{\r = 0.55+1, \i = 1+1}{2}{\rput(-0.55,\r){$\mathrm{M\i}$}}
  \Gantt(0,1)[5]{}
  \Gantt(5,1)[3]{J2}
  \Gantt(8,1)[4]{J1}
  \Gantt(12,1)[7]{}
  \Gantt(0,2)[3]{J1}
  \Gantt(3,2)[2]{J2}
  \Gantt(5,2)[14]{}
\end{pspicture}
\end{center}

\end{document}

output

13
  • thank you but how can i insert more numbers and m1 m2 and j1 j2, like torbon posted.
    – Milo Li
    Commented Dec 26, 2016 at 11:10
  • @Torbjørn T. thank you man, but how can i put the numbers on the left, 5 must be under the dash next to J2
    – Milo Li
    Commented Dec 26, 2016 at 11:10
  • 1
    @MiloLi See updated answer. Commented Dec 26, 2016 at 14:47
  • but 5 is not under the dash next to j2 ? how could i change that and thanks for your quick answer..
    – Milo Li
    Commented Dec 26, 2016 at 18:54
  • I don't understand your question; in the screenshot of the produced output from my code, 5 is indeed under J2 in the bottom line. Commented Dec 27, 2016 at 5:30

You must log in to answer this question.

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