我正在编写一个课程大纲,其中课程表以表格形式显示。我使用包\AdvanceDate
中的命令\advdate
将日期提前两天或五天。这在表格之外运行良好。在表格内部,它会继续相对于命令\today
设置的原始值而不是命令更新的\SetDate
值提前。\today
\AdvanceDate
换句话说,在表内部,\AdvanceDate
的作用类似于\DayAfter
,它总是重置\today
。
\documentclass{article}
\usepackage{datetime}
\usepackage{advdate}
\newdateformat{mydate}{\THEDAY\ \shortmonthname[\THEMONTH]}
\begin{document}
\SetDate[23/08/2016]
\mydate\today
\AdvanceDate[2] \mydate\today
\AdvanceDate[5] \mydate\today
\AdvanceDate[2] \mydate\today
\AdvanceDate[5] \mydate\today
\medskip
In table format:
\SetDate[23/08/2016]
\begin{tabular}{@{}l@{}}
\mydate\today \\
\AdvanceDate[2]\mydate\today \\
\AdvanceDate[5]\mydate\today \\
\AdvanceDate[2]\mydate\today \\
\AdvanceDate[5]\mydate\today \\
\end{tabular}
\end{document}
答案1
每个单元格都会tabular
创建一个组,其中更改的范围是有限的。在这种特殊情况下,日期推进不会超出单元格的范围,这意味着当您移动到下一行(或单元格)时,它会恢复到原始值。
您可以更新 的定义\AdvanceDate
以进行\global
以下更改 \day
:
\documentclass{article}
\usepackage{datetime,advdate}
\newdateformat{mydate}{\THEDAY\ \shortmonthname[\THEMONTH]}
\makeatletter
\renewcommand\AdvanceDate[1][\@ne]{\global\advance\day#1 \FixDate}
\makeatother
\begin{document}
\SetDate[23/08/2016]
\mydate\today
\AdvanceDate[2] \mydate\today
\AdvanceDate[5] \mydate\today
\AdvanceDate[2] \mydate\today
\AdvanceDate[5] \mydate\today
\medskip
In table format:
\SetDate[23/08/2016]
\begin{tabular}{@{}l@{}}
\mydate\today \\
\AdvanceDate[2]\mydate\today \\
\AdvanceDate[5]\mydate\today \\
\AdvanceDate[2]\mydate\today \\
\AdvanceDate[5]\mydate\today
\end{tabular}
\end{document}