我该如何使用pgfgantt
排版 2013 年的日历?我希望日历能够显示相应月份的日期;它应该显示 1、...、31、1、...、28、1、...31 等,而不是 1 到 365 的数字。
另外,如果这些日期中的周六和周日可以用不同的背景突出显示,那就太好了。到目前为止,我有以下内容:
\documentclass{article}
\usepackage[paperwidth=300cm, paperheight=50cm,left=1cm,right=1cm,top=5cm,bottom=5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfgantt}
\usepackage{pgfcalendar}
\begin{document}
\begin{ganttchart}[hgrid, vgrid, x unit=0.8cm]{365}
\gantttitle{Projektplan}{365} \\
\gantttitlelist{1,...,365}{1} \\
\ganttbar{Task 1}{2}{5} \\
\end{ganttchart}
\end{document}
答案1
这是 David 提供的一个小捷径(考虑到他甚至不使用 PGF :D,这真是太棒了)。
\documentclass{article}
\usepackage[paperwidth=300cm, paperheight=50cm,
left=1cm,right=1cm,top=5cm,bottom=5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfgantt}
\usetikzlibrary{calendar}
\protected\def\zzz#1{%
\pgfcalendarifdate{2012-12-31+#1}{weekend}% Test if it's a weekend
{\textcolor{red}{\pgfcalendarifdateday}}% Typeset with red color
{\pgfcalendarifdateday}% Or just the number
}
\begin{document}
\begin{ganttchart}[hgrid, vgrid, x unit=0.8cm]{365}
\gantttitle{Projektplan}{365} \\
\gantttitlelist[
title list options={var=\y, evaluate=\y as \x using {"\zzz{\y}"}}
]{1,...,365}{1} \\
\ganttbar{Task 1}{2}{5} \\
\end{ganttchart}
\end{document}
答案2
\documentclass{article}
\usepackage[paperwidth=300cm, paperheight=50cm,left=1cm,right=1cm,top=5cm,bottom=5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfgantt}
\usepackage{pgfcalendar}
\newcount\startdate
\newcount\daynum
\pgfcalendardatetojulian{2012-01-01}{\startdate}
\protected\def\zzz{%
\pgfcalendarjuliantodate{\numexpr\startdate\relax}{\year}{\month}{\day}%
\pgfcalendarjuliantoweekday\startdate\daynum
\day
{\ifnum\daynum=6\color{red}%
\pgfcalendarweekdayshortname{\daynum}%
\fi}%
\global\advance\startdate1}
\begin{document}
\begin{ganttchart}[hgrid, vgrid, x unit=0.8cm]{365}
\gantttitle{Projektplan}{365} \\
\gantttitlelist[
title list options={var=\y,evaluate=\y as \x using
"{\zzz}"}
]{1,...,365}{1} \\
\ganttbar{Task 1}{2}{5} \\
\end{ganttchart}
\end{document}