The labels of \ganttbar
in pgfgantt
are right aligned by default (at the border of chart).
Is it possible to have it left aligned?
[Tex/LaTex] Alignment of the bar labels of ganttbar
pgfgantttikz-pgf
Related Solutions
Code (Update)
\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfgantt}
\makeatletter
\ganttset{
prog default/.initial=100,
prog/.code={
\pgfutil@in@{:}{#1}
\ifpgfutil@in@
\pgfqkeysalso{/pgfgantt}{@prog={#1}}
\else
\pgfqkeysalso{/pgfgantt}{@prog={\pgfkeysvalueof{/pgfgantt/prog default}:#1}}
\fi
},
@prog/.code args={#1:#2}{
\pgfqkeysalso{/pgfgantt}{progress=100, progress label text={#2 (#1\,\%)}}
}
}
\makeatother
\ganttset{progress label anchor/.append style={text=red}}
\begin{document}
\begin{ganttchart}[y unit title=0.4cm,
y unit chart=0.5cm,
vgrid={draw=none, dotted},
hgrid,
title label anchor/.style={below=-1.6ex},
title left shift=.05,
title right shift=-.05,
title height=1,
bar/.style={fill=gray!50},
incomplete/.style={fill=white},
progress label text={},
bar height=0.7,
group right shift=0,
group top shift=.6,
group height=.3,
group peaks={}{}{.2},
]{12}
\gantttitle{2012}{12} \\
\gantttitle{October}{4}
\gantttitle{November}{4}
\gantttitle{December}{4} \\
\ganttgroup{Group 1}{1}{8}\\
\ganttbar[prog=50: Resource 1]{Task 1}{1}{2} \\
\ganttbar[prog= Resource 2]{Task 2}{3}{4} \\
\ganttbar[prog= Resource 3]{Task 3}{5}{6}\\
\ganttbar[prog=50: Resource 1, progress label anchor/.append style={below=4pt}]{Task 4}{1}{8} \\
\end{ganttchart}
\end{document}
Output
Code
\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfgantt}
\makeatletter
\ganttset{
prog default/.initial=100,
prog/.code={
\pgfutil@in@{:}{#1}
\ifpgfutil@in@
\pgfqkeysalso{/pgfgantt}{@prog={#1}}
\else
\pgfqkeysalso{/pgfgantt}{@prog={\pgfkeysvalueof{/pgfgantt/prog default}:#1}}
\fi
},
@prog/.code args={#1:#2}{
\edef\pgf@tempa{#1}%
\ifx\pgf@tempa\tikz@nonetext
\pgfqkeysalso{/pgfgantt}{progress={100},progress label text={#2}}
\else
\pgfqkeysalso{/pgfgantt}{progress={#1},progress label text={#2 (##1\,\%)}}
\fi
}
}
\makeatother
\ganttset{progress label anchor/.append style={text=red}}
\begin{document}
\begin{ganttchart}[y unit title=0.4cm,
y unit chart=0.5cm,
vgrid={draw=none, dotted},
hgrid,
title label anchor/.style={below=-1.6ex},
title left shift=.05,
title right shift=-.05,
title height=1,
bar/.style={fill=gray!50},
incomplete/.style={fill=white},
progress label text={},
bar height=0.7,
group right shift=0,
group top shift=.6,
group height=.3,
group peaks={}{}{.2},
]{12}
\gantttitle{2012}{12} \\
\gantttitle{October}{4}
\gantttitle{November}{4}
\gantttitle{December}{4} \\
\ganttgroup{Group 1}{1}{8}\\
\ganttbar[prog=50: Resource 1]{Task 1}{1}{2} \\
\ganttbar[prog= Resource 2]{Task 2}{3}{4} \\
\ganttbar[prog=none:Resource 3]{Task 3}{5}{6}\\
\ganttbar[prog=50: Resource 1, progress label anchor/.append style={below=4pt}]{Task 4}{1}{8} \\
\end{ganttchart}
\end{document}
Output
The option name
to ganttbar
allows you to change the name of the element to whatever you want. Use this as
\ganttbar[name=myname]{Title}{1}{3}
and thereafter refer to this element as myname
.
\documentclass{article}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[x unit=2cm,vgrid]{1}{4}
\ganttbar[name=t1] {Task 1}{1}{2} \\
\ganttbar[name=t2] {Task 2}{2}{3} \\
\ganttbar[name=t3] {Task 3}{1}{2} \\
\ganttbar[name=t4] {Task 4}{2}{3}
\ganttlink {t1}{t2}
\ganttlink {t3}{t4}
\end{ganttchart}
\medbreak
\begin{ganttchart}[x unit=2cm,vgrid]{1}{4}
\ganttbar[name=t1] {Task 1}{1}{2} \\
%\ganttbar[name=t2] {Task 2}{2}{3} \\
\ganttbar[name=t3] {Task 3}{1}{2} \\
\ganttbar[name=t4] {Task 4}{2}{3}
%\ganttlink {t1}{t2}
\ganttlink {t3}{t4}
\end{ganttchart}
\end{document}
Best Answer
If the question is about the label text align then you can use a coordinate intersection as follows:
This would give
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 thedraw
option to the anchor style keys to see if it is working properly and simply can be removed later.