8

I would like to draw an arbitration scheduling scheme. I tried to draw one with xfig, but the result is... not so nice ;-):

enter image description here

Does anyone know a good way to draw this in LaTeX? The result don't have to be exactly like my example. I also tried the pgfgantt package, but don't know how to change the right border from the bar of "Master 3"...

\begin{ganttchart}[vgrid, hgrid]{15}
\ganttbar{Master 1}{7}{9} \\
\ganttbar{Master 2}{2}{4} \\
\ganttbar{Master 3}{5}{6} \ganttbar{}{10}{10} \\
\ganttbar{Master 4}{11}{13}
\end{ganttchart}
4

2 Answers 2

6

With a few adjustments (the path picture bounding box is clipped against the path picture), a few empirical values (the .6\pgflinewidth probably won’t work for other line widths) and without vertical correction of the bar (the same reason as before), one can achieve the following.

Code

\documentclass[tikz]{standalone}
\usepackage{pgfgantt}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{Shift/.style 2 args={shift={(+#1.5\pgflinewidth,+#2.5\pgflinewidth)}}}
\newcommand*{\pgfkeysstylelet}[2]{\expandafter\let\csname pgfk@#1/.@cmd\expandafter\endcsname\csname pgfk@#2/.@cmd\endcsname}
\ganttset{
    /tikz/broken/.style={
        decoration={
            name=zigzag,
            amplitude=+1pt,
            segment length=+2pt}},
    broken right/.code={
        \pgfkeysstylelet{/pgfgantt/bar backup}{/pgfgantt/bar}
        \pgfkeysalso{
            /pgfgantt/bar left shift=-.5\pgflinewidth/\ganttvalueof{x unit},
            /pgfgantt/bar right shift=(.5\pgflinewidth+.5\pgfdecorationsegmentamplitude)/\ganttvalueof{x unit},
            /pgfgantt/bar/.append style={
                draw=none,
                path picture={
                    \draw[/pgfgantt/bar backup, broken] ([Shift=+-] path picture bounding box.north west) |-
                                                        ([Shift=-+, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.south east)
                                           decorate {-- ([Shift=--, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.north east)}
                                                     -- cycle;}}}},
    broken left/.code={
        \pgfkeysstylelet{/pgfgantt/bar backup}{/pgfgantt/bar}
        \pgfkeysalso{
            /pgfgantt/bar right shift=.5\pgflinewidth/\ganttvalueof{x unit},
            /pgfgantt/bar left shift=(-.5\pgflinewidth-.5\pgfdecorationsegmentamplitude)/\ganttvalueof{x unit},
            /pgfgantt/bar/.append style={
                draw=none,
                path picture={
                    \draw[/pgfgantt/bar backup, broken] ([Shift=--] path picture bounding box.north east) |-
                                                        ([Shift=++, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.south west)
                                           decorate {-- ([Shift=+-, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.north west)}
                                                     -- cycle;}}}}}
\begin{document}
\begin{ganttchart}[vgrid, hgrid]{15}
\ganttbar{Master 1}{7}{9} \\
\ganttbar{Master 2}{2}{4} \\
\ganttbar[broken right]{Master 3}{5}{6} \ganttbar[broken left]{}{10}{10} \\
\ganttbar{Master 4}{11}{13}
\end{ganttchart}
\end{document}

Output

enter image description here

enter image description here

1

Here is an adaptation of Qrrbrbirlbel's code so that you can make both the left and the right side of the ganttbar jagged:

\newcommand*{\pgfkeysstylelet}[2]{\expandafter\let\csname pgfk@#1/.@cmd\expandafter\endcsname\csname pgfk@#2/.@cmd\endcsname}
\ganttset{
    /tikz/broken/.style={
      decoration={
        name=zigzag,
        amplitude=+1pt,
        segment length=+2pt}},
    broken right/.code={
        \pgfkeysstylelet{/pgfgantt/bar backup}{/pgfgantt/bar}
        \pgfkeysalso{
            /pgfgantt/bar left shift=-.5\pgflinewidth/\ganttvalueof{x unit},
            /pgfgantt/bar right shift=(.5\pgflinewidth+.5\pgfdecorationsegmentamplitude)/\ganttvalueof{x unit},
            /pgfgantt/bar/.append style={
                draw=none,
                path picture={
                  \draw[/pgfgantt/bar backup, broken]
                  ([Shift=+-] path picture bounding box.north west) |-
                  ([Shift=-+, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.south east)
                  decorate {-- ([Shift=--, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.north east)}
                  -- cycle;
                }
            }
        }
    },
    broken left/.code={
        \pgfkeysstylelet{/pgfgantt/bar backup}{/pgfgantt/bar}
        \pgfkeysalso{
            /pgfgantt/bar right shift=.5\pgflinewidth/\ganttvalueof{x unit},
            /pgfgantt/bar left shift=(-.5\pgflinewidth-.5\pgfdecorationsegmentamplitude)/\ganttvalueof{x unit},
            /pgfgantt/bar/.append style={
                draw=none,
                path picture={
                  \draw[/pgfgantt/bar backup, broken]
                  ([Shift=--] path picture bounding box.north east) |-
                  ([Shift=++, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.south west)
                  decorate {-- ([Shift=+-, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.north west)}
                  -- cycle;
                }
            }
        }
    },
    broken both/.code={
        \pgfkeysstylelet{/pgfgantt/bar backup}{/pgfgantt/bar}
        \pgfkeysalso{
          /pgfgantt/bar left shift=(-.5\pgflinewidth-.5\pgfdecorationsegmentamplitude)/\ganttvalueof{x unit},
          /pgfgantt/bar right shift=(.5\pgflinewidth+.5\pgfdecorationsegmentamplitude)/\ganttvalueof{x unit},
            /pgfgantt/bar/.append style={
                draw=none,
                path picture={
                  \draw[/pgfgantt/bar backup, broken]
                  ([Shift=-+, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.south east)
                  decorate {-- ([Shift=--, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.north east)};
                  \draw[/pgfgantt/bar backup, broken]
                  ([Shift=++, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.south west)
                  decorate {-- ([Shift=+-, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.north west)};
                  \draw[/pgfgantt/bar backup, broken]
                  ([Shift=++, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.south west) --
                  ([Shift=-+, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.south east);
                  \draw[/pgfgantt/bar backup, broken]
                  ([Shift=--, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.north east) --
                  ([Shift=+-, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.north west);
                }
            }
        }
    }
}

So now you can write e.g: \ganttbar[broken both]{}{16}{18}. Perhaps this is useful to someone.

I noticed that this doesn't really work if you want to use fill colors. If someone can fix that I'd be very happy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.