我想使用 绘制甘特图pgfgantt
。使用默认设置,它会先绘制条形图,然后再绘制箭头/链接。因此,箭头会穿过条形图,我觉得这太丑了。是否可以更改此行为,例如定义绘制的 z 顺序?
最小工作示例:
\documentclass{article}
\usepackage{pgfgantt}
\begin{document}
\begin{tikzpicture}
\begin{ganttchart}[bar/.append style={orange}, link/.append style={thick}]{1}{6}
\ganttbar{Task 1}{1}{2} \\
\ganttbar{Task 2}{3}{4} \\
\ganttbar{Task 3}{5}{6}
\ganttlink[link type=f-s]{elem0}{elem1}
\ganttlink{elem0}{elem2}
\end{ganttchart}
\end{tikzpicture}
\end{document}
该示例适用于 pgfgantt.sty 版本 4.0。
答案1
将 设置canvas
为fill=none
,可以简单地使用backgrounds
库和on background layer
键来绘制“任务 2”后面的箭头。我还将 设置outer xsep
为零,以便f-s
线条完全笔直。
为了避免“任务 2”下箭头交叉的歧义,我会像下面的示例 Y 那样画箭头。(你也可以想到只有添加 已建立的link bulge
值。
代码 X
\documentclass[tikz,convert=false]{standalone}
\usepackage{pgfgantt}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{ganttchart}[
/pgf/outer xsep=+0pt,
bar/.append style={orange},
canvas/.append style={fill=none},
link/.append style={thick}]{1}{6}
\ganttbar{Task 1}{1}{2} \\
\ganttbar{Task 2}{3}{4} \\
\ganttbar{Task 3}{5}{6}
\ganttlink[link type=f-s]{elem0}{elem1}
\begin{scope}[on background layer]
\ganttlink{elem0}{elem2}
\end{scope}
\end{ganttchart}
\end{document}
输出 X
代码Y
\documentclass[tikz,convert]{standalone}
\usepackage{pgfgantt}
\newganttlinktype{rdldr*}{%
\draw [/pgfgantt/link]
(\xLeft, \yUpper) --
(\xLeft + \ganttvalueof{link bulge 1} * \ganttvalueof{x unit},
\yUpper) --
($(\xLeft + \ganttvalueof{link bulge 1} * \ganttvalueof{x unit},
\yUpper)!%
\ganttvalueof{link mid}!%
(\xLeft + \ganttvalueof{link bulge 1} * \ganttvalueof{x unit},
\yLower)$) --
($(\xRight - \ganttvalueof{link bulge 2} * \ganttvalueof{x unit},
\yUpper)!%
\ganttvalueof{link mid}!%
(\xRight - \ganttvalueof{link bulge 2} * \ganttvalueof{x unit},
\yLower)$) --
(\xRight - \ganttvalueof{link bulge 2} * \ganttvalueof{x unit},
\yLower) --
(\xRight, \yLower);%
}
\ganttset{
link bulge 1/.link=/pgfgantt/link bulge,
link bulge 2/.link=/pgfgantt/link bulge}
\begin{document}
\begin{ganttchart}[
bar/.append style={orange},
link/.append style={thick},
link bulge=.5]{1}{6}
\ganttbar{Task 1}{1}{2} \\
\ganttbar{Task 2}{3}{4} \\
\ganttbar{Task 3}{5}{6}
\ganttlink{elem0}{elem1}
\ganttlink[link type=rdldr*, link bulge 1=2.5, link mid=.75]{elem0}{elem2}
\end{ganttchart}
\begin{ganttchart}[
bar/.append style={orange},
link/.append style={thick},
link bulge=.5]{1}{6}
\ganttbar{Task 1}{1}{2} \\
\ganttbar{Task 2}{3}{4} \\
\ganttbar{Task 3}{5}{6}
\ganttlink{elem0}{elem1}
\ganttlink[link type=rdldr*, link bulge 2=2.5, link mid=.25]{elem0}{elem2}
\end{ganttchart}
\end{document}