根据给定的开始时间,我想自动计算时间表。基于https://groups.google.com/forum/#!topic/de.comp.text.tex/BQrRUYmDrHw我把以下 MWE 放在一起:
\documentclass{beamer}
\newcount\hours
\newcount\minutes
\def\gettime#1:#2\relax#3#4{\def#3{#1}\def#4{#2}}
\newcommand{\add}[2]{%
\expandafter\gettime#1\relax{\hrs}{\mins}%
\expandafter\gettime#2\relax{\addhrs}{\addmins}%
\hours=\hrs\relax%
\advance\hours by \addhrs\relax%
\minutes=\mins\relax%
\advance\minutes by \addmins\relax%
\ifnum\minutes>59\relax%
\advance\minutes by -60\relax%
\advance\hours by 1\relax%
\else%
\ifnum\minutes<0\relax%
\advance\minutes by 60\relax%
\advance\hours by -1\relax%
\fi%
\fi%
\ifnum\hours>23\relax%
\advance\hours by -24\relax%
\else%
\ifnum\hours<0\relax%
\advance\hours by 24\relax%
\fi%
\fi%
\ifnum\minutes<10\relax%
\xdef#1{\number\hours:0\number\minutes}%
\else%
\xdef#1{\number\hours:\number\minutes}%
\fi%
}
\begin{document}
\begin{frame}
\xdef\startTime{09:30}
\begin{tabular}{l l l}
top1 & \startTime{} -- \add\startTime{01:00}\startTime & \textcolor{red}{01:00}\\
top2 & \startTime{} -- \add\startTime{00:45}\startTime & \textcolor{red}{00:45}\\
top3 & \startTime{} -- \add\startTime{00:15}\startTime & \textcolor{red}{00:15}\\
\hline
Sum & \textcolor{red}{09:30} -- \startTime
\end{tabular}
\end{frame}
\end{document}
现在的问题是:
我怎样才能自动插入红色表示的时间?[第三列中的值是持续时间]
答案1
我很困惑,因为看起来行尾的红色时间只是添加的持续时间\startTime
,而第二列底部的红色条目只是初始开始时间……所以您需要做的就是记住这些值。
假设情况确实如此,如果您将这些定义添加到序言中:
\newcounter{top}
\newcommand\newStartTime[1]{\refstepcounter{top}%
Top\arabic{top}&\startTime{}--\add\startTime{#1}\startTime& #1\\}
\newenvironment{StartTimes}[1]{%
\def\InitialStartTime{#1}\xdef\startTime{09:30}%
\tabular{lll}Heat & Time & Duration\\\hline}%
{\hline Sum& \InitialStartTime--\startTime\endtabular}
然后你可以使用以下命令生成表格:
\begin{StartTimes}{09:30}
\newStartTime{01:00}
\newStartTime{00:45}
\newStartTime{00:15}
\end{StartTimes}
得出的结果为: