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.

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
1  
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
add comment

3 Answers

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.

\documentclass{standalone}
\usepackage{pgfgantt}

\begin{document}
\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}
\end{ganttchart}
\end{document}

enter image description here

share|improve this answer
add comment

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

\documentclass{article}
\usepackage{tikz,pgfgantt}
\begin{document}
\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}
\end{ganttchart}
    \node[fill,circle,inner sep=2pt] at (b1) {}; %This line is for demo
    \draw[dashed] (o) |- (b1); % This too!
\end{tikzpicture}
\end{document}

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
add comment

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)

\documentclass{article}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
    vgrid,
    hgrid,
    bar label font=\Large,
    bar label text={--#1$\rightarrow$},
    bar label anchor/.append style={align=left, text width=8em}
]{12}
    \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}
\end{ganttchart}
\end{document}
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
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.