![pgfgantt 中的垂直线仅覆盖一行](https://linux22.com/image/445730/pgfgantt%20%E4%B8%AD%E7%9A%84%E5%9E%82%E7%9B%B4%E7%BA%BF%E4%BB%85%E8%A6%86%E7%9B%96%E4%B8%80%E8%A1%8C.png)
下面是我得到的结果的一个例子:
\documentclass[10pt,a4paper]{article}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
expand chart=\textwidth,
vgrid=true, hgrid=true,
canvas/.style={draw=none},
include title in canvas=false,
y unit title=0.5cm,
y unit chart=0.6cm,
title/.style={draw=none, fill=none},
title label font=\footnotesize
]{0}{14}
\gantttitlelist{0,...,14}{1}\\
\ganttbar{$\tau_1$}{0}{0}
\ganttbar[inline]{}{3}{3} \ganttbar[inline]{}{6}{6}
\ganttbar[inline]{}{9}{9} \ganttbar[inline]{}{12}{12}
\\
\ganttbar{$\tau_2$}{2}{2} \ganttbar{}{7}{7}
\\
\ganttbar{$\tau_3$}{4}{5} \ganttbar{}{8}{8}
\end{ganttchart}
\end{document}
我想绘制仅覆盖一行的垂直线。例如,在标有 $\tau_1$ 的行上,单元格 0、3、6、9、12 的左侧应该有线条。在 $\tau_2$ 行上,单元格 2、7、12 的左侧应该有线条。在 $\tau_3$ 上,单元格 2 和 12 的左侧应该有线条。
我知道 pgfgantt 具有绘制垂直线的功能,但我找不到任何可以绘制不覆盖整个网格的垂直线的功能。
答案1
我找不到任何内置方式来做到这一点,但你可以定义自己的风格:
\documentclass[10pt,a4paper]{article}
\usepackage{pgfgantt}
\begin{document}
\newganttchartelement*{vline}{
vline/.style={
draw, dotted, outer sep=0 pt, inner sep=0 pt,
},
vline right shift=-1,
vline top shift=0,
vline height=1,
}
\begin{ganttchart}[
expand chart=\textwidth,
% vgrid=true,
hgrid=true,
canvas/.style={draw=none},
include title in canvas=false,
y unit title=0.5cm,
y unit chart=0.6cm,
title/.style={draw=none, fill=none},
title label font=\footnotesize
]{0}{14}
\gantttitlelist{0,...,14}{1}\\
\ganttbar{$\tau_1$}{0}{0}
\ganttvline{}{0} \ganttvline{}{3} \ganttvline{}{6} \ganttvline{}{9} \ganttvline{}{12}
\ganttbar[inline]{}{3}{3} \ganttbar[inline]{}{6}{6}
\ganttbar[inline]{}{9}{9} \ganttbar[inline]{}{12}{12}
\\
\ganttbar{$\tau_2$}{2}{2}
\ganttvline{}{2} \ganttvline{}{7} \ganttvline{}{12}
\ganttbar{}{7}{7}
\\
\ganttbar{$\tau_3$}{4}{5}
\ganttvline{}{2} \ganttvline{}{12}
\ganttbar{}{8}{8}
\end{ganttchart}
\end{document}