5

I am using a simple example of gantt charts for a beamer presentation. My code for the gantt chart is the following:

\begin{frame}
\frametitle{Gantt Charts}
\begin{ganttchart}{1}{12}
\gantttitle{2016}{12} \\
\gantttitlelist{1,...,12}{1} \\
\ganttgroup{Group 1}{1}{7} \\
\ganttbar{Task 1}{1}{2} \\
\ganttlinkedbar{Task 2}{3}{7} \ganttnewline
\ganttmilestone{Milestone}{7} \ganttnewline
\ganttbar{Final Task}{8}{12}
\ganttlink{elem2}{elem3}
\ganttlink{elem3}{elem4}
\end{ganttchart}

\end{frame}

My question is the following: how can I fit the chart in my beamer frame?

3
  • Can you make a complete example? If I add that chart to a standard beamer document it fits perfectly. Mar 14, 2016 at 12:51
  • I updated my examlpe, with how my page is look like. Maybe my problem is due to the template I am using which is custom. Is there a way to force the chart to be in the page anyway?
    – Jose Ramon
    Mar 14, 2016 at 12:54
  • Another solution also valid for beamer class: tex.stackexchange.com/a/59041/1952
    – Ignasi
    Mar 14, 2016 at 14:32

1 Answer 1

5

You can reduce the height by setting the y unit title and y unit chart to a smaller value. The default is 1cm. If you need to compress things horizontally you can add x unit=0.4cm (default is 0.5cm). To compress further you should reduce the font size as well, which can be done by modifying the styles X label font, where X is title, bar, group, milestone. See code below.

With 48 months it will be very cramped, but it might work. If all else fails, you can place the whole pgfgantt environment in a \resizebox, demonstrated in the second frame. The first two arguments to \resizebox is the width and height, the ! means that the aspect ratio should be preserved, so that length is calculated.

\documentclass{beamer}
\usepackage{pgfgantt}
\begin{document}
\begin{frame}
\frametitle{Gantt charts}
\begin{ganttchart}[
x unit=0.22cm,
y unit title=0.5cm,
y unit chart=0.5cm,
title label font=\fontsize{4}{5}\selectfont,
bar label font=\tiny,
group label font=\tiny\bfseries,
milestone label font=\tiny\itshape,
]{1}{48}
\gantttitle{2011}{12} \\
\gantttitlelist{1,...,12}{1} \\
\ganttgroup{Group 1}{1}{7} \\
\ganttbar{Task 1}{1}{2} \\
\ganttlinkedbar{Task 2}{3}{7} \ganttnewline
\ganttmilestone{Milestone}{7} \ganttnewline
\ganttbar{Final Task}{8}{12}
\ganttlink{elem2}{elem3}
\ganttlink{elem3}{elem4}
\end{ganttchart}
\end{frame}

\begin{frame}
\frametitle{Gantt charts}
\resizebox{10cm}{!}{\begin{ganttchart}{1}{48}
\gantttitle{2011}{12} \\
\gantttitlelist{1,...,12}{1} \\
\ganttgroup{Group 1}{1}{7} \\
\ganttbar{Task 1}{1}{2} \\
\ganttlinkedbar{Task 2}{3}{7} \ganttnewline
\ganttmilestone{Milestone}{7} \ganttnewline
\ganttbar{Final Task}{8}{12}
\ganttlink{elem2}{elem3}
\ganttlink{elem3}{elem4}
\end{ganttchart}}
\end{frame}
\end{document}

enter image description here

2
  • Since my chart is for 48 months, I have also to resize me fonts in order to fit in the screen. Any idea how to resize my fonts or to fit my fonts to their correspondant cells?
    – Jose Ramon
    Mar 14, 2016 at 13:00
  • I updated the answer. (This demonstrates why a complete, realistic example is useful. Saves multiple iterations and guesses about setup.) Mar 14, 2016 at 13:17

You must log in to answer this question.

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