我遇到了一个问题:我希望我的甘特图有两种类型的标签——一种在图表的侧面,一种在内联——但我很难让它工作。我用来生成图表的代码如下:
\begin{ganttchart}[
vgrid,
x unit=1cm,
title height=1]{12}{12}
\gantttitle{Quarters}{12} \\
\gantttitlelist{1,...,12}{1} \\
\gantttitle{Year 1}{4}
\gantttitle{Year 2}{4}
\gantttitle{Year 3}{4}\\
\ganttbar{WP1 Theoretical part}{1}{5} \\
\ganttbar{WP1 Experimental part}{2}{6} \\
\ganttbar{WP2 Theoretical part}{7}{11}\\
\ganttbar{WP2 Experimental part}{8}{12}\\
\ganttbar[bar/.append style={fill=gray,pattern=north east lines}]{WP3 Theoretical part}{6}{12}\\
\ganttbar[bar/.append style={fill=gray,pattern=north east lines}]{WP3 Experimental part}{7}{12}
\end{ganttchart}
这个想法是将 WPx 标签放在图表左侧,但将“理论/实验部分”标签放在条形图内。是否可以使用 pgfgantt 来实现这一点?
答案1
您可以使用两个\ganttbars
;第二个使用inline
选项。下面是这种方法,通过一个命令:
\Dganttbar{<side text>}{<inline text>}{<start>}{<end>}
代码:
\documentclass{article}
\usepackage{pgfgantt}
\newcommand\Dganttbar[4]{%
\ganttbar{#1}{#3}{#4}\ganttbar[inline,bar label font=\footnotesize]{#2}{#3}{#4}
}
\begin{document}
\begin{ganttchart}{1}{12}
\gantttitle{2011}{12} \\
\gantttitlelist{1,...,12}{1} \\
\Dganttbar{WP1}{Theoretical part}{1}{5} \\
\Dganttbar{WP1}{Experimental part}{2}{6} \\
\Dganttbar{WP2}{Theoretical part}{7}{11}\\
\Dganttbar{WP2}{Experimental part}{8}{12}\\
\end{ganttchart}
\end{document}