如何縮放甘特圖?

如何縮放甘特圖?

草圖:

我試圖擴大規模甘特圖為了適應 Beamer 演示。

假設我有一些比演示矩形大的甘特圖:

 \begin{figure}
   \begin{gantt}{20}{20}
     \begin{ganttitle}
       \numtitle{2012}{1}{2016}{4}
     \end{ganttitle}

     %% lots of activities
     \ganttbar{1}{0}{3}
     ...
     ...
     \ganttbar{1}{0}{19}
     %% lots of activities
   \end{gantt}
 \end{figure}

問題: 如何縮放這個圖形以固定在投影機框架中?

例子: 如果我使用一些 PNG 圖像,我肯定會這樣做:

\begin{figure}
  \includegraphic[scale=0.5]{mypngpic.png}
\end{figure}

但在甘特環境中並沒有(至少我還不知道)一種擴展的方式。

答案1

由於它gantt是基於 TikZ,因此從外部強制縮放也可以。我沒有仔細檢查程式碼,但也許有可能直接向環境提供選項gantt。它有自己的密鑰系統,但無法識別比例選項。

\documentclass{article}
\usepackage{gantt}
\begin{document}
\tikzset{every picture/.style={yscale=0.3,transform shape}}
   \begin{gantt}{5}{12}
     \begin{ganttitle}
       \numtitle{2012}{1}{2014}{4}
     \end{ganttitle}
     %% lots of activities
     \ganttbar{1}{0}{3}
     \ganttbar{1}{0}{10}
     %% lots of activities
   \end{gantt}

\tikzset{every picture/.style={yscale=1,transform shape}}
   \begin{gantt}{5}{12}
     \begin{ganttitle}
       \numtitle{2012}{1}{2014}{4}
     \end{ganttitle}
     %% lots of activities
     \ganttbar{1}{0}{3}
     \ganttbar{1}{0}{10}
     %% lots of activities
   \end{gantt}

\end{document}

在此輸入影像描述 另請注意,還有另一個基於 TikZ 的軟體包pgfgantt

答案2

將內容放在\begin{gantt}{20}{20}......\end{gantt}一個文件中,例如myganttfig1.tex.然後在你的主 tex 檔中使用\resizebox如下:

%=========================
\begin{figure}[htb]
\centering{
\resizebox{0.62\textwidth}{!}{\input{myganttfig1.tex}}}
\caption{your caption \label{fig:mygantt1}
\end{figure}
%===========================

您可以更改寬度0.62\textwidth和高度!以滿足您的需求。此參數{!}確保在決定高度時保持縱橫比不變。

正如 Gonzalo 在他的評論中指出的那樣,在這種特殊情況下,同時使用高度和寬度會更合適。

相關內容