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.

Is it possible to reduce the default vertical space between bars in pgfgantt? The manual specifies "last line height" but there appears to be no "line height" option.

\documentclass[a4paper,11pt]{article}
\usepackage{pgfgantt}
\begin{document}
\section{}


\begin{tikzpicture}[x=3cm, y=0.75cm]  
\begin{ganttchart}[bar={fill=red!50}]{5}
\gantttitle{2012--2017}{5} \\
\gantttitlelist{1,...,5}{1} \\
\ganttbar{PhD1}{1}{3.5} \\
\ganttbar{PhD2}{2.5}{5} \\
\end{ganttchart}
\end{tikzpicture}
\end{document}
share|improve this question

4 Answers 4

up vote 9 down vote accepted

I just submitted pgfgantt v2.0 to CTAN. Among several other new features, this version introduces the three keys x unit, y unit title and y unit chart. These keys should allow you to use different line heights in the title and the remainder of the chart.

share|improve this answer
    
Thanks very much. –  Raphael Oct 21 '11 at 13:28

The best I could do is to adjust the y-scale to y=0.50cm, and add bar top shift=-0.1, bar height=0.6 to get the horizontal bars the original height. This also necessitated tweaking the title setup, so am thinking that there must be a better way, but hopefully this helps:

\documentclass[a4paper,11pt]{article}
\usepackage{pgfgantt}
\begin{document}
\section{}

\begin{tikzpicture}[y=0.75cm]  
\begin{ganttchart}[bar={fill=red!50},vgrid, hgrid]{5}
\gantttitle{2012--2017}{5} \\
\gantttitlelist{1,...,5}{1} \\
\ganttbar{PhD1}{1}{3.5} \\
\ganttbar{PhD2}{2.5}{5} \\
\end{ganttchart}
\end{tikzpicture}
%
\begin{tikzpicture}[y=0.50cm]  
\begin{ganttchart}[bar={fill=red!50},vgrid, hgrid,
    title height=.75, title top shift=0,
    title label anchor={below=-1.5ex},
    bar top shift=-0.1, bar height=0.6]{5}
\gantttitle{2012--2017}{5} \\
\gantttitlelist{1,...,5}{1} \\
\ganttbar{PhD1}{1}{3.5} \\
\ganttbar{PhD2}{2.5}{5} \\
\end{ganttchart}
\end{tikzpicture}
\end{document}

enter image description here

The x=3cm was removed just to be able to show a before and after.

share|improve this answer
    
Thanks very much. –  Raphael Oct 3 '11 at 16:27

Hmmm, doesn't look like there are any ways to do this in the package directly. It's relatively easy to make it possible though. It does require modifying the package and to be honest I haven't tested the effect it has on linking, grouping, progress, etc. Although if there are problems they can be fixed in a similar manner. First we need to add an option key to affect linespacing. At the beginning of the sty file you will see a lot of keydefs, we add ours here. Lets call the key linespacing.

\@gtt@keydef{linespacing}

Then we add it to ganttset to ensure it's set to 1 by default. Just add linespacing=1, in the list. Now for the actual modifications we go to the ganttbar command. Here we have definitions for y@upper and y@lower these determine the dimensions of the bars. We modify them as follows:

\def\y@upper{\@gtt@get{linespacing}*\value{gtt@currentline}%
+\value{gtt@lasttitleline}-\@gtt@get{linespacing}*\value{gtt@lasttitleline}%
-\@gtt@get{bar top shift}}%
\def\y@lower{\@gtt@get{linespacing}*\value{gtt@currentline}%
+\value{gtt@lasttitleline}-\@gtt@get{linespacing}*\value{gtt@lasttitleline}%
-\@gtt@get{bar top shift}-\@gtt@get{bar height}}%

All we do is scale the newlines that are not in the title by the factor we assigned to linespacing.

You should note that changing a package in this way, especially without checking all the options like I have done here, is not recommended. It can give you a quick way to obtain what you want though. You should never modify the original package, make a copy, place it in your local tex tree and modify that, call it mypgfgantt.sty and include that instead.

Now you can create a picture with less linespacing as follows:

\documentclass[a4paper,11pt]{article}
\usepackage{mypgfgantt}
\begin{document}
 \begin{tikzpicture}
  \begin{ganttchart}[bar={fill=red!50}]{5}
   \gantttitle{2012--2017}{5} \\
   \gantttitlelist{1,...,5}{1} \\
   \ganttbar{PhD1}{1}{3.5} \\
   \ganttbar{PhD2}{2.5}{5} \\
  \end{ganttchart}
 \end{tikzpicture}
 %
 \begin{tikzpicture}
  \begin{ganttchart}[bar={fill=red!50},linespacing=0.5]{5}
   \gantttitle{2012--2017}{5} \\
   \gantttitlelist{1,...,5}{1} \\
   \ganttbar{PhD1}{1}{3.5} \\
   \ganttbar{PhD2}{2.5}{5} \\
  \end{ganttchart}
 \end{tikzpicture}
\end{document}

enter image description here

This is my first posting here, hope it's up to standards and this (kind of) solves your problem.

share|improve this answer
    
I uploaded the image for you. Welcome to TeX.SX! –  Torbjørn T. Oct 4 '11 at 12:00
    
Thanks. I have emailed the package author and will let you know if he replies. –  Raphael Oct 4 '11 at 16:37
    
I got a reply. He will look into it :) –  Raphael Oct 7 '11 at 12:59

in v4.0 from 2013/06/01 you can use something like:

\begin{ganttchart}[y unit chart=2cm]{0}{10}
\ganttbar{magic}{3}{8}\\
\ganttbar{magic2}{2}{8}\\
\end{ganttchart}

see page 7 official documentation

share|improve this answer
    
Hi, welcome to TeX.sx. This is just what is mentioned in the accepted answer by Wolfgang Skala, isn't it? –  Torbjørn T. Jan 1 at 20:59
    
For the ill-informed (like me), this provides a nice illustration of the accepted answer. –  Joost Sep 29 at 7:43

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.