如何将时间线与日历结合起来

如何将时间线与日历结合起来

我正在使用该pgfgantt包创建时间线。这是我目前得到的结果:

\documentclass[landscape]{article}
\usepackage[dvipsnames,usenames]{xcolor}
\usepackage{tikz}
\usepackage{pgfgantt}
\usepackage{pgfcalendar}
\renewcommand{\familydefault}{\sfdefault}
\definecolor{barblue}{RGB}{153,204,254}
\begin{document}
    \begin{tikzpicture}[x=1cm,y=1cm]
        \begin{ganttchart}%
            [canvas={fill=none, draw=black!5, line width=.75pt},
            hgrid style={draw=black!5, line width=.75pt},
            vgrid={draw=black!5, line width=.75pt},
            title={draw=none, fill=none},
            title label font=\bfseries\footnotesize,
            title label anchor={below=-2pt},
            include title in canvas=false,
            bar={draw=none, fill=barblue},
            ]{33}
        \gantttitle[title label anchor={below left=-2pt and -3pt}]{Date:}{0}
        \gantttitlelist[title list options={%
            var=\y, evaluate=\y as \x%
            using "\pgfcalendarweekdayshortname{\y}"%
        }]{0,...,6}{1} \\
        \ganttbar{Task 1}{1}{7} \\
        \ganttbar{Task 2}{8}{14} \\
        \ganttbar{Task 3}{15}{21} \\
        \end{ganttchart}
    \end{tikzpicture}
\end{document}

结果是这样的: 甘特图

这并不是我所期望的。我还想在星期名称旁边显示当前日期(例如:星期一,1.8.)。并且这应该重复几个星期。例如,我想有一个从今天开始的五周时间表,而无需手动填写所有日期。我不知道这些软件包是否可以做到这一点,但我真的很感激任何帮助。

答案1

您可以使用\pgfcalendar宏来代替默认\pgffor使用的宏\gantttitlelist,如下所示:

\documentclass[landscape]{article}
\usepackage[dvipsnames,usenames]{xcolor}
\usepackage{tikz}
\usepackage{pgfgantt}
\usepackage{pgfcalendar}
\renewcommand{\familydefault}{\sfdefault}
\definecolor{barblue}{RGB}{153,204,254}
\begin{document}
    \begin{tikzpicture}[x=1cm,y=1cm]
        \begin{ganttchart}%
            [canvas={fill=none, draw=black!5, line width=.75pt},
            hgrid style={draw=black!5, line width=.75pt},
            vgrid={draw=black!5, line width=.75pt},
            title={draw=none, fill=none},
            title label font=\bfseries\footnotesize,
            title label anchor={below=-2pt},
            include title in canvas=false,
            bar={draw=none, fill=barblue},
            ]{33}
        \gantttitle[title label anchor={below left=-2pt and -3pt}]{Date:}{0}
%        \gantttitlelist[title list options={%
%            var=\y, evaluate=\y as \x%
%            using "\pgfcalendarweekdayshortname{\y}"%
%        }]{0,...,6}{1} \\
        \pgfcalendar{titlecal}{2011-09-21}{2011-10-12}{%
          \gantttitle{\pgfcalendarweekdayshortname{\pgfcalendarcurrentweekday} 
          \pgfcalendarcurrentday}{1}}\\
        \ganttbar{Task 1}{1}{7} \\
        \ganttbar{Task 2}{8}{14} \\
        \ganttbar{Task 3}{15}{21} \\
        \end{ganttchart}
    \end{tikzpicture}
\end{document}

第一个参数(此处为“titlecal”)是所创建节点名称的前缀,此处并没有什么特别用处,但接下来的两个参数是开始和停止日期。您可以使用 PGF 手册第 57 节中的命令更改显示的实际文本。

相关内容