I have a Gantt produced with pgfgantt
package. However, when you try to center it centers the entire figure (including names of the tasks).
I would like to have the table centered, and then the names and other things floating relative to it.
I imagine that the tikzpicture
has some type of anchor set in the center of the entire set of items to center the image. So, I was wondering if it is possible to shift that anchor to the center of the table, instead of the whole figure.
I went through the manual, but couldn't find information on this regard. I tried to show what I mean by "centering the table" in the figures below. Note that due to the crop I used to produce the image the margins are out, but imagine the margins around the caption of the image.
\documentclass{article}
\usepackage{pgfgantt}
\pagestyle{empty}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}
\begin{ganttchart}{1}{12}
\ganttbar{Task with really long name}{1}{2} \\
\end{ganttchart}
\end{tikzpicture}
\caption{Not centered on the table.}
\end{figure}
\begin{figure}[h]
\hspace*{-40px}% manually adjusted
\begin{tikzpicture}
\begin{ganttchart}{1}{12}
\ganttbar{Task with really long name}{1}{2} \\
\end{ganttchart}
\end{tikzpicture}
\caption{Kind of centered on the table.}
\end{figure}
\end{document}
Best Answer
Here's a bit of a roundabout way. Put the whole
ganttchart
in apgfinterruptboundingbox
environment, which essentially means that it will not be considered when deciding the bounding box. Then addcanvas/.append style={alias=frame}
to theganttchart
options (see code below), and after theganttchart
environment set the bounding box explicitly withAll of this needs to be inside a
tikzpicture
environment, though if you just have theganttchart
environment the surroundingtikzpicture
is not required.Also note that you don't want to have
\\
after the lastganttbar
, as that creates some additional whitespace.