2

This question Gantt chart - columns and rows are not aligned showed some misaligned rows in a Gantt chart.

To my impression package pgfgantt doesn't provide the requested outcome per se. However, isolating the required changes, these could be introduced by placing more complicated Tikz-objects left of the \ganttbar element. (Question) However, I didn't find out, how to assign or retrive coordinates, e.g. from a placed \ganttbar element.

As an example the code below is taken from the pgfgantt manual, modified and taylored to demonstrate my question.

E.g. it's not possible to do sth. like:

    \ganttbar{Task 1}{1}{2} (A) \\
...
    \node[green] at (A) {hi};

While it is possible to place a \node in absolute (even guessed) coordinates, see the blue text below.

I tried using the special node bounding box with little to no success. Instead of having the coordinate of the blue colored ganttbar, it produces something else.

May be the label node, used to write down the tasks name on the left side, can be replace, overwritten, or accessed? (Here it's left empty for the manually placed blue text.)

\documentclass[10pt,border=3mm]{standalone}
\usepackage{pgfgantt}

\begin{document}
 \begin{ganttchart}{1}{12}
    \gantttitle{2011}{12} \\
    \gantttitlelist{1,...,12}{1} \\
    \ganttbar{Task 1}{1}{2} \\
    {
        \ganttbar[
            bar/.append style={draw=blue,fill=blue!20}
        ]{}{8}{12}
        [local bounding box=inner box]
        \node[red]  (inner box.east) {hi world};
    }
    
    \node[green] at (0,-1) {hi};
    \node[blue,anchor=east] at (0,-3.5) {show more complex things here};
\end{ganttchart}
\end{document}

result

1 Answer 1

3

You can make use of the name key to set a node name to a specific \ganttbar:

\documentclass[border=10pt]{standalone}
\usepackage{pgfgantt}

\begin{document}
 \begin{ganttchart}{1}{12}
    \gantttitle{2011}{12} \\
    \gantttitlelist{1,...,12}{1} \\
    \ganttbar{Task 1}{1}{2} \\
    \ganttbar[
        bar/.append style={
            draw=blue,
            fill=blue!20,
        },
        name=foo
    ]{}{8}{12}
    
    \node[red, anchor=south] at (foo.north) {hi world};
    \node[green] at (foo) {hi};
    
    \node[blue, anchor=east] at (0,-3.5) {show more complex things here};    
\end{ganttchart}
\end{document}

enter image description here

2
  • Great, thank you. I was suspecting it, but didn't find it in the manual (searching for name is futil, while name= would do ...). Very good.
    – MS-SPO
    Commented Dec 7, 2023 at 11:09
  • 1
    @MS-SPO I checked the code of the package actually. It was not clear to me first either. Commented Dec 7, 2023 at 12:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .