[Tex/LaTex] Fit a gantt chart in a beamer frame

beamerchartspgfgantt

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?

Best Answer

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