Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

here's a problem I have: I want my gantt bars to have two types of labels -- one on the side of the chart, and one inline -- and I'm having a hard time making it work. The code I use to generate the chart is listed below:

\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}

And the idea is to have WPx labels on the left of the chart, but "Theoretical/experimental part" labels inside the bars. Is it possible to make this with pgfgantt?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

You could use two \ganttbars; the second one using the inline option. Below, this approach, thorough a command:

\Dganttbar{<side text>}{<inline text>}{<start>}{<end>}

The code:

\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}

enter image description here

share|improve this answer
    
brilliant and simple, thanks! –  pkazmierczak Feb 23 at 17:37
    
@pkazmierczak You're welcome! I edited my answer suppressing a superfluous ` \\ ` command. –  Gonzalo Medina Feb 23 at 18:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.