1

Is it possible to add text below the x-axis in a Gantt chart. For example, assume I have a simple Gantt chart with two tasks

\begin{ganttchart}[vgrid, hgrid]{12}
\gantttitle{Title}{12} \\
\ganttbar{Task 1}{0}{3} \\
\ganttbar{Task 2}{3}{10} 
\end{ganttchart}

I'd like to add text below some of the vertical grid lines in the Gantt chart. For example, below the vertical grid line where Task 1 ends I'd like to add the text "T_1" and add "T_2" below the vertical grid line where Task 2 starts. Is this possible?

1

Here's one way to do it using a variation of Paul Gessler's nice answer to How to draw a vertical line at a specified date in a Gantt chart?:

\documentclass{article}
\usepackage{pgfgantt}

\makeatletter
\@gtt@keydef{anyday}{none}
\@gtt@keydef{anyday offset}{1}
\@gtt@stylekeydef{anyday rule}{dashed, line width=1pt}
\@gtt@keydef{anyday label font}{\normalfont}
\@gtt@stylekeydef{anyday label node}{%
  anchor=north, font=\ganttvalueof{anyday label font}%
}

\newcount\gtt@anyday@slot

\newcommand\gantText[2]{%
  \gtt@tsstojulian{#1}{\gtt@anyday@slot}%
  \gtt@juliantotimeslot{\gtt@anyday@slot}{\gtt@anyday@slot}%
  \pgfmathsetmacro\y@upper{%
    \gtt@lasttitleline * \ganttvalueof{y unit title}%
  }%
  \pgfmathsetmacro\y@lower{%
    \gtt@lasttitleline * \ganttvalueof{y unit title}%
      + (\gtt@currentline - \gtt@lasttitleline - 1)%
      * \ganttvalueof{y unit chart}%
  }%
  \pgfmathsetmacro\x@mid{%
    (\gtt@anyday@slot - 1 + \ganttvalueof{anyday offset})%
      * \ganttvalueof{x unit}%
  }%
  \node [/pgfgantt/anyday label node]
     at (\x@mid pt, \y@lower pt) {#2};
}
\makeatother

\begin{document}

\begin{ganttchart}[vgrid, hgrid]{1}{12}
\gantttitle{Title}{12} \\
\ganttbar{Task 1}{1}{3} \\
\ganttbar{Task 2}{3}{12}  \\
\gantText{3}{$T_1$}
\gantText{2}{$T_2$}
\end{ganttchart}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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