6

Is there a way to get a straight line to a milestone in pgfgantt?

If the end of the preceding ganttbar is on the same date as the milestone, a line from the tail to the start looks strange:

\documentclass{article}
\usepackage{pgfgantt}
\begin{document}
  \begin{ganttchart}{1}{4}
    \ganttbar[name=e1]{My bar}{2}{3}\\
    \ganttmilestone[name=e2]{My milestone}{3}
    \ganttlink[link type=f-s]{e1}{e2}
  \end{ganttchart}
\end{document}

enter image description here

3
  • Would be a solution without the package pgfgantt ok, too? Aug 1, 2018 at 16:54
  • @current_user I do not think that it is necessary to redo the diagram in TikZ. You could simply define a new link style with \newgantlinktype, and the syntax is TikZ. Of course, it would be helpful to know what the OP wants.
    – user121799
    Aug 1, 2018 at 17:01
  • 1
    You could just replace \ganttlink[link type=f-s]{e1}{e2} by \draw[-latex] (e1.south east) -- (e2.north) node[midway,right]{\emph{finish-start}};.
    – user121799
    Aug 1, 2018 at 17:20

2 Answers 2

5

You can define a new link type as proposed by marmot (see page 45 of the package manual [version 5.0]), like this:

\documentclass{article}
\usepackage{pgfgantt}

\newganttlinktype{f-m}{
 \ganttsetstartanchor{on right=1}
 \ganttsetendanchor{on left=0}
 \draw[/pgfgantt/link]
  ([xshift=-.2pt]\xLeft, \yUpper) --       % xshift to fit arrow
  node[pos=.5, /pgfgantt/link label node] {\ganttlinklabel} 
  (\xRight, \yLower);
}
\setganttlinklabel{f-m}{a fancy link}

\begin{document}
  \begin{ganttchart}{1}{4}
    \ganttbar[name=e1]{My bar}{2}{3}\\
    \ganttmilestone[name=e2]{My milestone}{3}
    \ganttlink[link type=f-m]{e1}{e2}
  \end{ganttchart}
\end{document}

Which would result in:

enter image description here

Or without label:

\documentclass{article}
\usepackage{pgfgantt}

\newganttlinktype{f-m}{
 \ganttsetstartanchor{on right=1}
 \ganttsetendanchor{on left=0}
 \draw[/pgfgantt/link]
  ([xshift=-.2pt]\xLeft, \yUpper) -- 
  (\xRight, \yLower);
}

\begin{document}
  \begin{ganttchart}{1}{4}
    \ganttbar[name=e1]{My bar}{2}{3}\\
    \ganttmilestone[name=e2]{My milestone}{3}
    \ganttlink[link type=f-m]{e1}{e2}
  \end{ganttchart}
\end{document}
1
  • Thanks for the nice solution, which makes nice use of pgfgantts synatex for creating new links. Aug 2, 2018 at 16:11
3

So, this is just a proposal.

\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{arrows}
\begin{document}
    \begin{tikzpicture}[>=latex,every node/.style={font=\sf}]
        \draw (0,0) rectangle (3,3);
        \draw (.5,2) rectangle (2.5,2.5);
            \fill[xshift=2.5cm,yshift=.5cm,black,rotate=45] (0,0) rectangle (.4,.4);
        \node[left] at (0,2.5) {My bar};
        \node[left] at (0,.5) {My milestone};
            \draw[red,->] (2.5,2) -- (2.5,1.1) node[fill=white,midway,right] {\tiny finish-to-start};
    \end{tikzpicture}
\end{document}

enter image description here

2
  • You could just take the OP's code and add your TikZ command, something like \draw[red,->] (e1.south east) -- (e2.north) node[fill=white,midway,right] {\emph{finish-to-start}};. And please add a screen shot of the result such that other people upvote you. ;-)
    – user121799
    Aug 1, 2018 at 17:25
  • 1
    Thanks a lot for the answer and even more for the helpful comment. It is of course nice to have such a short workaround. Aug 2, 2018 at 16:12

You must log in to answer this question.

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