11

I'm trying to use pgfgantt to create a gantt chart for a project spanning many weeks, thus the following code would overflow through the right margin. I can't find a way to alter the size of the grid elements or time slots:

\begin{tikzpicture}[x=.5cm, y=1cm]
\begin{ganttchart}%
[vgrid, hgrid]{50} % 50 weeks
\gantttitle{Title}{12} \\
\ganttbar{Task 1}{1}{4} \\
\ganttbar{Task 2}{5}{6} \\
\ganttmilestone{M 1}{6} \\
\ganttbar{Task 3}{7}{11}
\ganttlink{4}{2}{5}{3}
\ganttlink[b-m]{6}{3}{6}{4}
\ganttlink[m-b]{6}{4}{7}{5}
\end{ganttchart}
\end{tikzpicture}

My former question above, however here's a new angle...

How can I make pgfgantt scale everything by limiting its size to specific parameters? ex. I want it to span the full textwidth of the page or the full width save for the margins.

1
  • 1
    Could you turn your code snippet into a compilable document by adding the necessary preamble and \begin{document}?
    – Jake
    Jun 8, 2012 at 7:05

4 Answers 4

16

With command \resizebox{new width}{new height}{what you want to resize} you can change dimensions of any latex box. This means that everything (text, lines, simbols, ...) will be adjusted to new dimensions. In first or second parameter you can use ! in order to keep original aspect ratio. With this command,

\documentclass{article}
\usepackage{lipsum}
\usepackage{pgfgantt}

\begin{document}
\lipsum[1]

\noindent\resizebox{\textwidth}{!}{
\begin{tikzpicture}[x=.5cm, y=1cm]
\begin{ganttchart}%
[vgrid, hgrid]{50} % 50 weeks
\gantttitle{Title}{12} \\    
\ganttbar{Task 1}{1}{4} \\    
\ganttbar{Task 2}{5}{6} \\    
\ganttmilestone{M 1}{6} \\    
\ganttbar{Task 3}{7}{11}
%\ganttlink{4}{2}{5}{3}
%\ganttlink[b-m]{6}{3}{6}{4}
%\ganttlink[m-b]{6}{4}{7}{5}
\end{ganttchart}
\end{tikzpicture}
}

\lipsum[2]
\end{document}

your Gantt chart would look something like:

enter image description here

Update: Solution for pgfgantt 4.0

As is stated in Missing number treated as zero in gantttitle, last version of pgfgantt is not completely backwards compatible. And now ganttchar needs two mandatory arguments

\begin{ganttchar}[options]{<start tss>}{<end tss>} 

Therefore, previous example should be:

\documentclass{article}
\usepackage{lipsum}
\usepackage{pgfgantt}

\begin{document}
\lipsum[1]

\noindent\resizebox{\textwidth}{!}{
\begin{tikzpicture}[x=.5cm, y=1cm]
\begin{ganttchart}[vgrid, hgrid]{1}{50} % 50 weeks
\gantttitle{Title}{12} \\   
\ganttbar{Task 1}{1}{4} \\    
\ganttbar{Task 2}{5}{6} \\    
\ganttmilestone{M 1}{6} \\    
\ganttbar{Task 3}{7}{11}
%\ganttlink{4}{2}{5}{3}
%\ganttlink[b-m]{6}{3}{6}{4}
%\ganttlink[m-b]{6}{4}{7}{5}
\end{ganttchart}
\end{tikzpicture}
}

\lipsum[2]
\end{document}
2
  • above code is not working
    – Micky K
    Aug 2, 2015 at 6:51
  • @MickyK A new solution for last pgfgantt version has been added.
    – Ignasi
    Aug 2, 2015 at 16:46
3

[fr] tu peux jouer sur l'échelle de la figure s'il y a des noeuds, il faudra aussi ajouter transform shape mais cela risque de ne plus être très joli

[en] you can play on the global scale of the figure if there are knots, it will also add transform shape but this may not be very pretty

\documentclass[A4]{article}
\usepackage{tikz}
\usepackage{lipsum}

\begin{document}


\noindent \begin{tikzpicture}[scale=\textwidth/8cm]
\draw (0,0) rectangle (8,3);
\end{tikzpicture}

\lipsum[1]

\noindent \begin{tikzpicture}[scale=\textwidth/8cm,transform shape]
\node [rectangle,minimum width=8cm,minimum height=3cm,draw]{aaa};
\end{tikzpicture}

\end{document}

enter image description here

2

For those who look at this question recently, the later versions of pgfgantt exposed the expand chart parameter. You can set that parameter to whatever works for you. For example:

  \begin{ganttchart}[
    expand chart=\textwidth,
    hgrid,
    vgrid,
    time slot format=isodate-yearmonth,
    time slot unit=month]{2021-10}{2023-5}
    \gantttitlecalendar{year, month} \\
    \ganttbar{the task}{2022-1}{2022-2}
  \end{ganttchart}

See 2.3 The Canvas in the documentation.

0

One partial solution seems to use x unit and y unit to shrink the size of the time slots. This solves my first question.

I will wait for any potential answer for my second question. :)

You must log in to answer this question.

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