pgfgantt:标签未正确居中

pgfgantt:标签未正确居中

我正在尝试创建甘特图,并找到了这个很棒的包 pgfgantt。但是,我的标签没有正确居中在框中。我做错了什么吗?有没有办法得到我想要的结果?(我四处寻找答案,但找不到。如果我错过了,我深表歉意。)

以下是代码:

\documentclass{standalone}
\usepackage{pgfgantt}
\definecolor{grey}{gray}{0.75}
\begin{document}
\begin{ganttchart}[hgrid, inline, bar height = 1, bar top shift = 0, x unit = .7cm, y unit chart= .4cm]{17}
\ganttbar[bar/.style={fill=grey}]{\ }{0.00000}{1.00000}
\ganttbar{1}{1.00000}{2.00000}
\ganttbar[bar/.style={fill=grey}]{\ }{2.00000}{3.00000}
\ganttbar{4}{3.00000}{8.00000}
\\
\ganttbar[bar/.style={fill=grey}]{\ }{0.00000}{1.00000}
\ganttbar{2}{1.00000}{3.00000}
\ganttbar[bar/.style={fill=grey}]{\ }{3.00000}{4.00000}
\ganttbar{5}{4.00000}{15.00000}
\\
\ganttbar[bar/.style={fill=grey}]{\ }{0.00000}{1.00000}
\ganttbar{3}{1.00000}{4.00000}
\ganttbar[bar/.style={fill=grey}]{\ }{4.00000}{5.00000}
\ganttbar{6}{5.00000}{17.00000}
\end{ganttchart}
\end{document}

我无法发布生成的 pdf,因为我是新用户,但也许你仍然可以在这里看到它

答案1

对齐正确居中,但您创建的甘特图重叠。第二个和第三个参数中的数字\ganttbar表示一种槽值,而不是 (x) 坐标。请参阅以下更正后的 MWE:

\documentclass{standalone}
\usepackage{pgfgantt}
\definecolor{grey}{gray}{0.75}
\begin{document}
\begin{ganttchart}[hgrid, inline, bar height = 1, bar top shift = 0, x unit = .7cm, y unit chart= .4cm]{17}
\ganttbar[bar/.style={fill=grey}]{}{1}{1} % starts in slot 1, ends in slot 1, width=1 slot
\ganttbar{1}{2}{3}                        % starts in slot 2, ends in slot 3, width=2 slots
\ganttbar[bar/.style={fill=grey}]{}{4}{4} % starts in slot 4, ends in slot 4, width=1 slot
\ganttbar{3}{5}{8.00000}                  % starts in slot 5, ends in slot 8, width=4 slots
 \ganttnewline
\ganttbar[bar/.style={fill=grey}]{}{1}{1}
\ganttbar{2}{2}{3}
\ganttbar[bar/.style={fill=grey}]{}{4}{4}
\ganttbar{5}{5}{15}
 \ganttnewline
\ganttbar[bar/.style={fill=grey}]{}{1}{1}
\ganttbar{3}{2}{4}
\ganttbar[bar/.style={fill=grey}]{}{5}{5}
\ganttbar{6}{6}{17}
\end{ganttchart}
\end{document} 

甘特图示例

相关内容