如何向甘特图添加图例?

如何向甘特图添加图例?

我正在使用该pgfgantt包绘制甘特图,并且针对不同的任务类型使用不同的填充图案(即任务栏的填充图案)。效果很好!但我想添加一个图例来告诉读者哪种图案代表哪种任务。

我确实相信从内部这是不可能的pgfgantt,但也许还有其他方法可以添加它?

答案1

我想我不明白这个问题,但你可以在环境中添加你想要的东西gantt。这里我添加了一个节点,但你需要用它current bounding box来在 tikzpicture 周围或内部放置一个对象。

在此处输入图片描述

\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} 
\node[fill=white,draw] at ([yshift=-12pt]current bounding box.south){Box South};
\node[fill=white,draw,anchor=west] at (current bounding box.north east){Box North East}; 
\end{ganttchart}
\end{center}
\caption{Gantt Chart}
\end{figure}

\end{document}

相关内容