pgfgantt:直线至里程碑顶部中间

pgfgantt:直线至里程碑顶部中间

有没有办法在 pgfgantt 中获得一条直线到达里程碑?

如果前一个甘特图的末尾与里程碑在同一天,则从尾部到开头的一条线看起来很奇怪:

\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}

在此处输入图片描述

答案1

您可以按照 marmot 的建议定义一种新的链接类型(参见包装手册[版本 5.0]),如下所示:

\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}

这将导致:

在此处输入图片描述

或者不带标签:

\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}

答案2

所以,这只是一个提议。

\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}

在此处输入图片描述

相关内容