使用 pgfgantt 绘制 LaTeX 甘特图

使用 pgfgantt 绘制 LaTeX 甘特图

我尝试了给出的例子这里

\documentclass{article}
\usepackage{pgfgantt}

\begin{document}

\begin{figure}[ftbp]
\begin{center}

\begin{ganttchart}[y unit title=0.4cm,
y unit chart=0.5cm,
vgrid,hgrid, 
title label anchor/.style={below=-1.6ex},
title left shift=.05,
title right shift=-.05,
title height=1,
bar/.style={fill=gray!50},
incomplete/.style={fill=white},
progress label text={},
bar height=0.7,
group right shift=0,
group top shift=.6,
group height=.3,
group peaks={}{}{.2}]{24}
%labels
\gantttitle{Week}{24} \\
\gantttitle{Monday}{4} 
\gantttitle{Tuesday}{4} 
\gantttitle{Wednesday}{4} 
\gantttitle{Thursday}{4} 
\gantttitle{Friday}{4} 
\gantttitle{Saturday}{4} \\
%tasks
\ganttbar{first task}{1}{2} \\
\ganttbar{task 2}{3}{8} \\
\ganttbar{task 3}{9}{10} \\
\ganttbar{task 4}{11}{15} \\
\ganttbar[progress=33]{task 5}{20}{22} \\
\ganttbar{task 6}{18}{19} \\
\ganttbar{task 7}{16}{18} \\
\ganttbar[progress=0]{task 8}{21}{24}

%relations 
\ganttlink{elem0}{elem1} 
\ganttlink{elem0}{elem3} 
\ganttlink{elem1}{elem2} 
\ganttlink{elem3}{elem4} 
\ganttlink{elem1}{elem5} 
\ganttlink{elem3}{elem5} 
\ganttlink{elem2}{elem6} 
\ganttlink{elem3}{elem6} 
\ganttlink{elem5}{elem7} 
\end{ganttchart}
\end{center}
\caption{Gantt Chart}
\end{figure}

\end{document}

我可能忘记安装某个软件包,但 Tex Live 显示已安装 pgfgantt。我收到很多错误。前两个是:

! LaTeX Error: Unknown float option `f'.
! Package pgfkeys Error: I do not know the key '/pgfgantt/group peaks', to whic h you passed '{}{}{.2}', and I am going to ignore it. Perhaps you misspelled it . See the pgfkeys package documentation for explanation. Type H <return> for immediate help.... \gantttitle

你能帮助我吗?提前谢谢。

答案1

  • 没有f环境选项float,请将其删除。

  • 您正在尝试的示例使用的是旧版本pgfgantt。对于当前版本 5.0,您必须更改三件事。

    • group peaks={}{}{.2}从 的选项中删除ganttchart
    • {24}将环境参数替换ganttchart{1}{24}
    • incomplete变为bar incomplete。在下面的例子中,我删除了该键,因为当前默认设置可能就是您想要的。

在此处输入图片描述

\documentclass{article}
\usepackage{pgfgantt}

\begin{document}

\begin{figure}[tbp]
  \begin{center}
    \begin{ganttchart}[
      y unit title=0.4cm,
      y unit chart=0.5cm,
      vgrid,
      hgrid, 
      title label anchor/.style={below=-1.6ex},
      title left shift=.05,
      title right shift=-.05,
      title height=1,
      progress label text={},
      bar height=0.7,
      group right shift=0,
      group top shift=.6,
      group height=.3
      ]{1}{24}

      % labels
      \gantttitle{Week}{24} \\
      \gantttitle{Monday}{4}
      \gantttitle{Tuesday}{4}
      \gantttitle{Wednesday}{4}
      \gantttitle{Thursday}{4} 
      \gantttitle{Friday}{4} 
      \gantttitle{Saturday}{4} \\

      % tasks
      \ganttbar{first task}{1}{2} \\
      \ganttbar{task 2}{3}{8} \\
      \ganttbar{task 3}{9}{10} \\
      \ganttbar{task 4}{11}{15} \\
      \ganttbar[progress=33]{task 5}{20}{22} \\
      \ganttbar{task 6}{18}{19} \\
      \ganttbar{task 7}{16}{18} \\
      \ganttbar[progress=0]{task 8}{21}{24}

      % relations 
      \ganttlink{elem0}{elem1} 
      \ganttlink{elem0}{elem3} 
      \ganttlink{elem1}{elem2} 
      \ganttlink{elem3}{elem4} 
      \ganttlink{elem1}{elem5} 
      \ganttlink{elem3}{elem5} 
      \ganttlink{elem2}{elem6} 
      \ganttlink{elem3}{elem6} 
      \ganttlink{elem5}{elem7} 
    \end{ganttchart}
  \end{center}
  \caption{Gantt Chart}
\end{figure}

\end{document}

相关内容