我想创建一个以周为增量的日期序列,该序列应显示在表格环境中。
我一直在摆弄这个论坛上发布的代码片段(在 LaTeX 中生成日期序列) 使用 advdate 来实现此目的。但是,当您在表环境中使用这些命令时,日期不再递增。
这里你可以看到一个显示问题的最小工作示例。提前致谢!
\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}
答案1
使用本质上相同的代码,但通过datenumber
包,可以在表格中和表格外部正常工作。
\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}