在下面的 MWE 中
\documentclass{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
vgrid,
hgrid,
bar/.append style={fill=red!50},
group/.append style={draw=black, fill=green!50},
milestone/.append style={fill=orange, rounded corners=3pt}
]{1}{12}
\gantttitle{Project}{12} \\
\ganttbar{Task 1}{1}{3} \\
\ganttbar[bar/.append style={fill=yellow} ]{Task 1}{2}{8} \\
\ganttbar[bar/.append style={fill=green} ]{Task 1}{5}{7}
\end{ganttchart}
\end{document}
有没有办法将多个甘特图合并到同一标题“任务 1”下?
理想情况下是这样的(或者最好降低栏高)
答案1
您可以将多个\ganttbar
s 放在一行中,然后缩放高度并相应地移动它们。仅将标签放在第一个栏中。
为了获得正确的垂直对齐,建议同时调整bar height
和bar top shift
。在下面的例子中,我使用了bar height=.2
和bar top shift=.4
。我添加了两个普通条形图来显示输出对比:
\documentclass{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
vgrid,
hgrid,
bar/.append style={fill=red!50},
]{1}{12}
\gantttitle{Project}{12} \\
\ganttbar[bar/.append style={fill=yellow}]{Task 2}{2}{8} \\
\ganttbar[bar height=.2, bar top shift=.4, bar/.append style={yshift=.2cm}]{Task 1}{1}{3}
\ganttbar[bar height=.2, bar top shift=.4, bar/.append style={fill=yellow}]{}{2}{8}
\ganttbar[bar height=.2, bar top shift=.4, bar/.append style={fill=green, yshift=-.2cm}]{}{5}{7} \\
\ganttbar[bar/.append style={fill=yellow}]{Task 2}{2}{8}
\end{ganttchart}
\end{document}
答案2
作为一种简单的解决方案,您可以简单地保留前两个条形的标签,而只保留中间的标签,如下所示:
\documentclass{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
vgrid,
hgrid,
bar/.append style={fill=red!50},
group/.append style={draw=black, fill=green!50},
milestone/.append style={fill=orange, rounded corners=3pt}
]{1}{12}
\gantttitle{Project}{12} \\
\ganttbar{}{1}{3} \\
\ganttbar[bar/.append style={fill=yellow} ]{Task 1}{2}{8} \\
\ganttbar[bar/.append style={fill=green} ]{}{5}{7}
\end{ganttchart}
\end{document}