TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The labels of \ganttbar in pgfgantt are right aligned by default (at the border of chart). Is it possible to have it left aligned?

share|improve this question
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. – Marco Daniel Apr 16 '12 at 11:21
Do you really mean right? Maybe left? – Marco Daniel Apr 16 '12 at 11:21
yes sorry.. edited the question. – Gianni Apr 16 '12 at 11:53
up vote 6 down vote accepted

If the question is about the label text align then you can use a coordinate intersection as follows:

\begin{tikzpicture}[node distance=0cm]
\node[align=center] at (-4,0) (o) {This is\\ adjust node}; %Remove the text later or change it to a \coordinate
\begin{ganttchart}[vgrid, hgrid, bar label font=\Large,bar label text={--#1$\rightarrow$}]{12}
    \gantttitle{Title}{12} \\
    \ganttbar[name=b1,bar label anchor/.style={draw,right = of o|-b1}]{Task 1}{1}{3} \\
    \ganttbar[name=b2,bar label anchor/.style={draw,right = of o|-b2},bar label font=\color{orange}]{Task 2}{4}{10} \\
    \ganttbar[name=b3,bar label anchor/.style={draw,right = of o|-b3},bar label font=\MakeUppercase]{Final task}{11}{12}
    \node[fill,circle,inner sep=2pt] at (b1) {}; %This line is for demo
    \draw[dashed] (o) |- (b1); % This too!

This would give

enter image description here

As seen from the image we first provide an adjusting node. Since the north west point of the chart is the origin we just go left from the origin where I placed the node (o). Then we take the orthogonal intersection of this point and the bar center which is shown with a black dot and the intersection is shown with a dashed line. We put the bar labels' left side at these intersections hence they become left aligned. To be able to refer to each bar label we need to provide some names as can be seen from code.

Note that, I placed node distance=0cm to snap to the point without extra padding otherwise the labels would be as far as this key dictates. Moreover, I put the draw option to the anchor style keys to see if it is working properly and simply can be removed later.

share|improve this answer
Wow, i hoped is something more compact. Thanks for the great and clear explanation! – Gianni Apr 16 '12 at 12:30
@percusse: Done! – Jake Apr 16 '12 at 13:13

Another approach for left-aligning the bar labels is to use align=left, text width=<some value>, where <some value> should be large enough to accommodate the widest label. This approach has the advantage that you don't need to adjust the options for every bar; you only need to provide the keys once to the ganttchart environment.

(based on percusse's MWE)

    bar label font=\Large,
    bar label text={--#1$\rightarrow$},
    bar label anchor/.append style={align=left, text width=8em}
    \gantttitle{Title}{12} \\
    \ganttbar{Task 1}{1}{3} \\
    \ganttbar[bar label font=\color{orange}]{Task 2}{4}{10} \\
    \ganttbar[bar label font=\MakeUppercase]{Final task}{11}{12}
share|improve this answer
mmm this seems a good solution, and works very well, thanks Jake, However, i tried with groups and milestones (to have a nicely formatted chart), e.g. \begin{ganttchart} [bar label anchor/.append style={align=left, text width=16em}, [group label anchor/.append style={align=left, text width=16em}, [milestone label anchor/.append style={align=left, text width=16em}, y unit chart=0.5cm, x unit=0.35cm,vgrid={*2{white},*1{black, dashed}}]{36} but without any luck! where is the error? – Gianni Apr 17 '12 at 14:57
You have spurious [ in your options. The syntax is \begin{ganttchart}[ <first style>/.append style={<options>}, <second style>/.append style={<options>}, ... ] – Jake Apr 17 '12 at 15:17

The documentation of pgfgantt provides several examples. One of them is given below. The the Task 1 is centered (default) and Task 3 is right aligned.

The relevant key is bar label inline anchor/.style.


\begin{ganttchart}[vgrid, hgrid, inline]{12}
\gantttitle{Title}{12} \\
\ganttbar{Task 1}{1}{3}
\ganttbar[bar label inline anchor/.style=above]{Task 2}{5}{10} \\
\ganttbar[bar label shape anchor=left,%
bar label inline anchor/.style=right]{Task 3}{2}{7}
\ganttbar[inline=false]{Final task}{11}{12}

enter image description here

share|improve this answer

Your Answer


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.