![Pgfgantt:根据标题层级的网格线和标题分隔符](https://linux22.com/image/470988/Pgfgantt%EF%BC%9A%E6%A0%B9%E6%8D%AE%E6%A0%87%E9%A2%98%E5%B1%82%E7%BA%A7%E7%9A%84%E7%BD%91%E6%A0%BC%E7%BA%BF%E5%92%8C%E6%A0%87%E9%A2%98%E5%88%86%E9%9A%94%E7%AC%A6.png)
我正在尝试根据年份和季度组织甘特图。我无法设置网格和标题表行的格式。
我无法让标题部分中的水平线独立于垂直线格式。也就是说,两条红色箭头标注的水平线目前是虚线,而我希望它们是实线。
我无法让标题部分和主图表中的垂直线依赖于年份和季度格式。也就是说,图表中绿色箭头注释的垂直线和两条蓝色箭头注释的网格线是实线,而当前是虚线。
这是根据在线示例发布的屏幕截图的代码。
\ganttset{group/.append style={orange},
milestone/.append style={red},
progress label node anchor/.append style={text=red}}
\begin{ganttchart}[%Specs
y unit title=0.5cm,
y unit chart=0.7cm,
vgrid = {*2{black, dotted},*1{black,dashed}},
hgrid = true,
title height=1,
expand chart=\textwidth,
% title/.style={fill=none},
title label font=\bfseries\footnotesize,
bar/.style={fill=blue},
bar height=0.7,
% progress label text={},
group right shift=0,
group top shift=0.7,
group height=.3,
group peaks width={0.2},
inline]{1}{36}
%labels
% \gantttitle{A three-years project}{36}\\
% % title 1
\gantttitlelist[
title/.style={draw=black}]{"Year 1", "Year 2", "Year 3"}{12}\\
% \gantttitle[]{Year 1}{12}
% % title 2
% \gantttitle[]{Year 2}{12}
% % title 3
% \gantttitle[]{Year 3}{12} \\
% %
\gantttitlelist[
title/.style={draw=black, dashed, inner color=red}]{"Q1","Q2","Q3","Q4",
"Q1","Q2","Q3","Q4",
"Q1","Q2","Q3","Q4"}{3} \\
% Setting group if any
\ganttgroup[inline=false]{Group 1}{1}{5}\\
\ganttbar[progress=10,inline=false]{Planning}{1}{4}\\
\ganttmilestone[inline=false]{Milestone 1}{9} \\
\ganttgroup[inline=false]{Group 2}{6}{12} \\
\ganttbar[progress=2,inline=false]{test1}{10}{19} \\
\ganttmilestone[inline=false]{Milestone 2}{17} \\
\ganttbar[progress=5,inline=false]{test2}{11}{20} \\
\ganttmilestone[inline=false]{Milestone 3}{22} \\
\ganttgroup[inline=false]{Group 3}{13}{24} \\
\ganttbar[progress=90,inline=false]{Task A}{13}{15} \\
\ganttbar[progress=50,inline=false, bar progress label node/.append style={below left= 10pt and 7pt}]{Task B}{13}{24} \\ \\
\ganttbar[progress=30,inline=false]{Task C}{15}{16}\\
\ganttbar[progress=70,inline=false]{Task D}{18}{20} \\
\end{ganttchart}
答案1
您可以随时pgfgantt
使用基本 Ti 手动将内容添加到图表中钾Z 命令。您只需正确缩放x
,y
但您可以使用包提供的命令来pgfgantt
实现此目的:
\documentclass[border=10pt]{standalone}
\usepackage{pgfgantt}
\ganttset{
group/.append style={orange},
milestone/.append style={red},
progress label node anchor/.append style={text=red}
}
\begin{document}
\begin{ganttchart}[
y unit title=0.5cm,
y unit chart=0.7cm,
vgrid={*2{black, dotted}, *1{black, dashed}},
hgrid=true,
title height=1,
expand chart=\textwidth,
title label font=\bfseries\footnotesize,
bar/.style={fill=blue},
bar height=0.7,
group right shift=0,
group top shift=0.7,
group height=.3,
group peaks width={0.2},
inline
]{1}{36}
\gantttitlelist[
title/.style={draw=black}
]{"Year 1", "Year 2", "Year 3"}{12} \\
\gantttitlelist[
title/.append style={draw=none, inner color=red},
vgrid={*2{black, dotted}, *1{black, dashed}},
]{
"Q1", "Q2", "Q3", "Q4",
"Q1", "Q2", "Q3", "Q4",
"Q1", "Q2", "Q3", "Q4"
}{3} \\
\begin{scope}[x=\ganttvalueof{x unit}, y=\ganttvalueof{y unit title}]
\draw (0,-1) rectangle +({12 * 3},-1);
\foreach \y in {1,2} {
\draw ({\y*4*3},-1) -- +(0,-1);
}
\foreach \q in {1,2,3,5,6,7,9,10,11} {
\draw[dashed] ({\q*3},-1) -- +(0,-1);
}
\end{scope}
\ganttgroup[inline=false]{Group 1}{1}{5} \\
\ganttbar[progress=10, inline=false]{Planning}{1}{4} \\
\ganttmilestone[inline=false]{Milestone 1}{9} \\
\ganttgroup[inline=false]{Group 2}{6}{12} \\
\ganttbar[progress=2, inline=false]{test1}{10}{19} \\
\ganttmilestone[inline=false]{Milestone 2}{17} \\
\ganttbar[progress=5, inline=false]{test2}{11}{20} \\
\ganttmilestone[inline=false]{Milestone 3}{22} \\
\ganttgroup[inline=false]{Group 3}{13}{24} \\
\ganttbar[progress=90, inline=false]{Task A}{13}{15} \\
\ganttbar[
progress=50,
inline=false,
bar progress label node/.append style={below left=10pt and 7pt}
]{Task B}{13}{24} \\
\\
\ganttbar[progress=30,inline=false]{Task C}{15}{16} \\
\ganttbar[progress=70,inline=false]{Task D}{18}{20} \\
\end{ganttchart}
\end{document}