4

I would like to create a sequence of dates with weekly increments, which should be shown in a table environment.

I've been fiddling around with a code snippet posted in this forum (Generate a sequence of dates in LaTeX) which uses advdate for this purpose. However, when you use the commands inside a table environment, the date is no longer incremented.

Here you can see a minimal working example which shows the problem. Thanks in advance!

\documentclass{article}
\usepackage{advdate}

\newif\iffirst
\newcommand{\pnext}{%
  \AdvanceDate[7]% Step 3 days ahead...
  \iffirst
    \AdvanceDate\global\firstfalse% ...maybe 4
  \else
    \global\firsttrue
  \fi
  \today
}

\begin{document}

\ThisYear{2015}\ThisMonth{3}\ThisDay{30}

%The output of the following sequence is correct:
\today\par
\pnext\par
\pnext\par
\pnext\par
\pnext\par
\pnext

%However, it no longer works when the date is used in a table environment.
\begin{table}[hbtp]
\centering
  \begin{tabular}{ll}
\today\\
\pnext\\
\pnext\\
\pnext\\
\pnext\\
  \end{tabular}
\end{table}

\end{document}
2
  • Not a direct solution but I do exactly this with the datenumber package. I can post a solution using that package if you like.
    – Alan Munn
    Sep 1, 2015 at 18:29
  • I could do with any solution! I would greatly appreciate yours. I have fiddled around with the datenumber package, but it didn't work...
    – Thomas
    Sep 1, 2015 at 18:35

1 Answer 1

3

Using essentially the same code, but with the datenumber package, this works fine in both tables and outside of tables.

\documentclass{article}
\usepackage{datenumber}
\newif\iffirst
\newcommand{\pnext}{%
    \addtocounter{datenumber}{3}%
    \iffirst
        \addtocounter{datenumber}{1}%
        \global\firstfalse
    \else
        \global\firsttrue
    \fi
    \setdatebynumber{\thedatenumber}%
    \datedate
}

\begin{document}

\setdatenumber{2015}{3}{30}
%The output of the following sequence is correct:
\datedate\par
\pnext\par
\pnext\par
\pnext\par
\pnext\par
\pnext\par


%And it’s also correct in a table
\setdatenumber{2015}{3}{30}
\firstfalse
\begin{table}[hbtp]
\centering
\begin{tabular}{l}
\datedate\\
\pnext\\
\pnext\\
\pnext\\
\pnext\\
\pnext
\end{tabular}
\end{table}

\end{document}

output of code

4
  • A little problem: When trying to get a weekly sequence, it wrongly jumps from Oct 29 to Nov 6: \documentclass{article} \usepackage{datenumber} \newif\iffirst \newcommand{\pnext}{% \addtocounter{datenumber}{7}% \iffirst \addtocounter{datenumber}{1}% \global\firstfalse \else \global\firsttrue \fi \setdatebynumber{\thedatenumber}% \datedate } \begin{document} \setdatenumber{2015}{10}{22} \firstfalse \begin{table}[hbtp] \centering \begin{tabular}{l} \datedate\\ \pnext\\ \pnext\\ \pnext\\ \pnext\\ \pnext \end{tabular} \end{table} \end{document}
    – Thomas
    Sep 1, 2015 at 20:39
  • Even though this is surely not a problem of your script but a datenumber problem, you don't, by any chance, have an idea how to get a proper weekly sequence?
    – Thomas
    Sep 1, 2015 at 20:45
  • @Thomas if you are incrementing by 7 days, you should eliminate all the conditional code entirely. So to increment by 7 you need only \addtocounter{datenumber}{7}\setdatebynumber{\thedatenumber}\datedate
    – Alan Munn
    Sep 1, 2015 at 20:54
  • Belated congrats on joining the 100K club!!
    – Mico
    Sep 3, 2015 at 8:27

You must log in to answer this question.

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