pgfgantt
手册上说,必须使用vgrid={draw=none}
来移除网格的垂直线。但是,如何才能将移除限制到特定元素?具体来说,假设一个组和一个条形图如下所示。
\documentclass[border=3pt]{standalone}
\usepackage{pgfgantt}
\usepackage{tikz}
\begin{document}
\begin{ganttchart}[
x unit= 5mm,
y unit title=0.7cm,
y unit chart=0.9cm,
vgrid={*1{dashed}},
title height=1,
bar/.style={fill=blue},
bar height=1,
bar top shift=0,
]{1}{2}
\gantttitle{Time}{2}\\
\gantttitlelist{1,...,2}{1} \\
\ganttgroup[/pgfgantt/group/.style={font=\bfseries}]{Level 1: ...}{1}{2}
\ganttnewline[black]
\ganttbar{Requirement 1: ...}{1}{1}
\end{ganttchart}
\end{document}
有什么方法可以去除vgrid
驻留在组范围内的那些部分?
答案1
如果您只需要从vgrid
第一行中删除,您可能会说vgrid=*1{dashed, shorten <=0.9cm}
。但是,如果没有线条的行vgrid
应该位于图的中间,则这种方法不起作用。
我从中汲取灵感这个答案通过添加 为行的背景添加颜色。因此,您可以使用这种方法在需要的任何地方hgrid
绘制粗白线。您需要告诉选项您想要在哪里绘制这条线:vgrid
hgrid
\documentclass[border=3pt]{standalone}
\usepackage{pgfgantt}
\usepackage{tikz}
\tikzset{
grouprow/.style={
line width=\ganttvalueof{y unit chart},
yshift=-0.5*\ganttvalueof{y unit chart},
shorten >=.2pt,
shorten <=.2pt,
white
},
normalrow/.style={
opacity=0,
},
}
\begin{document}
\begin{ganttchart}[
x unit= 5mm,
y unit title=0.7cm,
y unit chart=0.9cm,
hgrid={*1{grouprow}, *2{normalrow}, *1{grouprow}, *1{normalrow}},
vgrid={*1{dashed}},
title height=1,
bar/.style={fill=blue},
bar height=1,
bar top shift=0,
]{1}{2}
\gantttitle{Time}{2}\\
\gantttitlelist{1,...,2}{1} \\
\ganttgroup[/pgfgantt/group/.style={font=\bfseries}]{Level 1: ...}{1}{2}
\ganttnewline[black]
\ganttbar{Requirement 1: ...}{1}{1}
\ganttnewline[black]
\ganttbar{Requirement 2: ...}{1}{1}
\ganttnewline[black]
\ganttgroup[/pgfgantt/group/.style={font=\bfseries}]{Level 2: ...}{1}{2}
\ganttnewline[black]
\ganttbar{Requirement 3: ...}{2}{2}
\end{ganttchart}
\end{document}