如何在 LaTeX-Beamer 中建立甘特圖

如何在 LaTeX-Beamer 中建立甘特圖

我正在嘗試在 Beamer 中創建甘特圖。我發現了以下範例:

\documentclass{beamer}

\usepackage[utf8]{inputenc}
\usepackage{pgfgantt}

\title{Sample title}
\author{Anonymous}
\institute{Overleaf}
\date{2019}


\begin{document}

\frame{\titlepage}
\begin{frame}{Gant-Chart}
    \begin{ganttchart}[vgrid, hgrid, 
                       bar/.append style={fill=blue!80},
                       milestone/.append style={fill=green}]{1}{15}
        \gantttitle{2019}{15} \\
        \gantttitlelist{1,...,15}{1} \\
        \ganttbar{Task 1}{1}{2} \\
        \ganttmilestone{Milestone}{7} \ganttnewline
        \ganttbar{Final Task}{8}{12}
    \end{ganttchart}
\end{frame} 


\end{document}

現在,我想稍微改變一下。第一行顯示年份。我希望第二行顯示月份。然後第三行顯示我為該任務計劃的周數。另外,我不想看到任何箭頭,而只想看到矩形。有沒有辦法加入網格?基本上,我希望所有內容都看起來像 Excel 表:網格,然後為我正在工作的矩形著色。

這是我想要的一個例子: 甘特圖

有人可以告訴我該怎麼做嗎?

這是另一個例子,它似乎非常接近我想要的。只是現在在周行中總是寫為「week 1」、「week 2」等等。我只想要號碼。

\begin{frame}
\begin{figure}[h!bt]
    \begin{center}
        \begin{ganttchart}[
            vgrid={*{6}{draw=none}, dotted},
            x unit=.08cm,
            y unit title=.6cm,
            y unit chart=.6cm,
            time slot format=isodate,
            time slot format/start date=2019-02-01]{2019-02-01}{2019-07-31}
            \ganttset{bar height=.6}
            \gantttitlecalendar{year, month=name, week} \\
            \ganttbar[bar/.append style={fill=blue}]{Task 1}{2019-02-11}{2019-02-17}\\
        \end{ganttchart}
    \end{center}
    \caption{Time Plan}
\end{figure}
\end{frame}

答案1

您的起點可能是:

\documentclass{standalone}

\usepackage[utf8]{inputenc}
\usepackage{pgfgantt}



\begin{document}

\begin{ganttchart}[
    hgrid,
    vgrid={*{6}{draw=none}, dotted},
    x unit=0.125cm,
    time slot format=isodate,
    time slot unit=day,
    calendar week text = {W\currentweek{}},
    bar height = 1, %necessary to make it fit the height
    bar top shift = -0.01, %to move it inside the grid space ;)
    ]{2019-01-01}{2019-06-30}
    \gantttitlecalendar{year, month=name, week} \\
    \ganttbar[bar/.append style={fill=red}]{Start}{2019-01-01}{2019-01-07}\\
        \ganttbar[bar/.append style={fill=yellow}]{A}{2019-01-08}{2019-01-14}\\
        \ganttbar[bar/.append style={fill=cyan}]{A}{2019-01-15}{2019-01-21}\\
                \ganttbar[bar/.append style={fill=green}]{Finish phase 1}{2019-01-22}{2019-01-28}
\end{ganttchart}


\end{document}

這使:

在此輸入影像描述

但請注意,您可以根據需要自訂這些甘特圖。只需查看獨立的 pgfgantt 包文件即可;-)

附:(正如所@Johannes_B指出的)如果您沒有收到問題的答案,請不要添加多餘的問題。

接下來,要將其安裝到您的投影機框架中,您可以adjustbox在序言中使用 package 並插入此片段,如下所示:

    \frame{\titlepage}
    \begin{frame}{Gant-Chart}
    \begin{adjustbox}{max totalsize={\textwidth}{.7\textheight},center}
    \begin{ganttchart}[
        hgrid,
        vgrid={*{6}{draw=none}, dotted},
        x unit=0.125cm,
        time slot format=isodate,
        time slot unit=day,
        calendar week text = {W\currentweek{}},
        bar height = 1, %necessary to make it fit the height
        bar top shift = -0.01, %to move it inside the grid space ;)
        ]{2019-01-01}{2019-06-30}
        \gantttitlecalendar{year, month=name, week} \\
        \ganttbar[bar/.append style={fill=red}]{Start}{2019-01-01}{2019-01-07}\\
        \ganttbar[bar/.append style={fill=yellow}]{A}{2019-01-08}{2019-01-14}\\
        \ganttbar[bar/.append style={fill=cyan}]{A}{2019-01-15}{2019-01-21}\\
        \ganttbar[bar/.append style={fill=green}]{Finish phase 1}{2019-01-22}{2019-01-28}
    \end{ganttchart}
\end{adjustbox}
\end{frame} 

筆記:其輸出與前一個相同,但現在縮放以適合文字寬度。

相關內容