使用电子表格计算时间

使用电子表格计算时间

我来自这个问题如何自动计算 LaTeX 表中的总和?

我想做同样的事情,但要进行“时间”计算。所以我的示例如下:

\documentclass{article}
\usepackage{spreadtab}
\begin{document}
  \begin{spreadtab}{{tabular}{llll|l}}
  @ a    & @ xyz      & @ duration      & @ starttime & @ endtime \\
  @ a1   & 5          & 00:03           & 00:00       & add(c2, d2) \\
  @ a2   & 9          & 00:01           & (automatically value of previous endtime)       & add(c3, d3) \\
  % and so on
  \end{spreadtab}
\end{document}

我必须做几十个这些会不时改变的事情,我只想改变持续时间,其他的都会被计算。

我强烈建议使用不使用 luaTeX 的解决方案。

答案1

基于时间计算

\documentclass{article}

\usepackage{}

\def\InitialStartTime{09:00}

\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
        \ifnum\hours<10\relax
            \xdef#1{0\number\hours:0\number\minutes}%
        \else
            \xdef#1{\number\hours:0\number\minutes}%
        \fi
    \else
        \ifnum\hours<10\relax
            \xdef#1{0\number\hours:\number\minutes}%
        \else
            \xdef#1{\number\hours:\number\minutes}%
        \fi 
    \fi
}

\newcommand\newStartTime[1]{#1 h~~ & \startTime{} & \add\startTime{#1}\startTime\\}

\begin{document}
    \xdef\startTime{\InitialStartTime}      
    \begin{tabular}{lllll}
        a  & xyz & duration & starttime & endtime\\
        \hline
        a1 & 5   & \newStartTime{00:03}
        a2 & 9   & \newStartTime{00:01}
    \end{tabular}           
\end{document}

在此处输入图片描述

相关内容