3

I am writing a syllabus that has the course schedule in a table. I am using the \AdvanceDate command in the \advdate package to advance the date by two or five days. This works fine outside a table. Inside a table, it continues to advance relative to the original value of \today set by the \SetDate command instead of the value of \today updated by the \AdvanceDate command.

In other words, inside a table, \AdvanceDate acts like \DayAfter, which always resets \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}

enter image description here

1

1 Answer 1

3

Each cell within a tabular creates a group within which the scope of changes are limited. In this particular case, the date advancement doesn't survive the scope of the cell, meaning it reverts back to the original value when you move to the next row (or cell).

You can update the definition of \AdvanceDate to make a \global change to \day:

enter image description here

\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}
3
  • Thank you for the clear explanation of the problem and then solving it. Commented Aug 16, 2016 at 19:35
  • If I add \mydate\today at the very end (just before \end{document}, I get the 37 August. Based on your explanation, I assume that is because the \FixDate command also doesn't survive the scope of the cell. Is there an easy fix?
    – mimuller
    Commented Dec 9, 2021 at 2:30
  • 1
    @mimuller: Yes. Try this version which does a \global\advance of all counters (\day, \month and \year), adding zero (\z@). This then fixes the date globally.
    – Werner
    Commented Dec 9, 2021 at 17:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .