我定义了一个 TeX 宏来比较日期和时间信息。在单个框内,没有问题,但如果在表格中使用,在不同的列或行中,如下所示,结果为 0。显然,框被取消装箱并刷新。我如何保存框 1(列/行)和框 2(列/行)的信息以便在第 3 列中处理,而无需再次输入它们?
\documentclass[a4paper]{article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
% \time
\newcount\hour %
\newcount\hours %
\newcount\minutes %
\hour=\time \divide\hour by 60
\minutes=\time
\hours=\hour \multiply\hours by 60
\advance \minutes by -\hours
%end \time
%begin definitions of caldate
\newcount\fromcalyear %%
\newcount\fromcalmonth %%
\newcount\fromcalday %%
\newcount\fromcalhour %%
\newcount\fromcalminutes %%
\newcount\tocalyear %%
\newcount\tocalmonth %%
\newcount\tocalday %%
\newcount\tocalhour %%
\newcount\tocalminutes %%
\def\fromcaldate[#1-#2-#3 #4:#5]{%
\fromcalyear=#1 %
\fromcalmonth=#2 %
\fromcalday=#3 %
\fromcalhour=#4 %
\fromcalminutes=#5 %
\ \the\fromcalyear-\ifnum\fromcalmonth<10
0\fi\the\fromcalmonth-\ifnum\fromcalday<10
0\fi\the\fromcalday\ \ifnum\fromcalhour<10
0\fi\the\fromcalhour:\ifnum\fromcalminutes<10 0\fi\the\fromcalminutes
\vskip0.1\baselineskip}%
\def\tocaldate[#1-#2-#3 #4:#5]{%
\tocalyear=#1 %
\tocalmonth=#2 %
\tocalday=#3 %
\tocalhour=#4 %
\tocalminutes=#5\ %
\the\tocalyear-\ifnum\tocalmonth<10
0\fi\the\tocalmonth-\ifnum\tocalday<10
0\fi\the\tocalday\ \ifnum\tocalhour<10
0\fi\the\tocalhour:\ifnum\tocalminutes<10 0\fi\the\tocalminutes
\advance\fromcalyear by -\tocalyear\multiply\fromcalyear by
-1 %
\advance\fromcalmonth by -\tocalmonth\multiply \fromcalmonth
by-1 %
\advance\fromcalday by -\tocalday \multiply \fromcalday by-1 %
\advance\fromcalhour by -\tocalhour \multiply \fromcalhour by-1 %
\advance\fromcalminutes by -\tocalminutes \multiply \fromcalminutes by-1 %
\vskip0.1\baselineskip}%
\def\rescaldatetime{(\the\fromcalyear)-(\the\fromcalmonth)-(\the\fromcalday) (\the\fromcalhour):(\the\fromcalminutes)}
\def\rescaldate{(\the\fromcalyear)-(\the\fromcalmonth)-(\the\fromcalday)}
\def\rescaltime{(\the\fromcalhour):(\the\fromcalminutes)}
\begin{document}
\begin{longtable}{p{3cm}p{3cm}p{3cm}}
\fromcaldate[2013-01-01 13:00]
\tocaldate[2014-02-04 14:11]
\rescaldatetime\\
\\
\fromcaldate[2013-01-01 13:00]&
\tocaldate[2014-02-04 14:11]&
\rescaldatetime\\
&&
\rescaldatetime\\
\end{longtable}
\end{document}
答案1
我不太清楚代码在做什么,但事实上这些值不可用与表格并无关系,除了表格单元格形成一个组:如果您用{...}
值包围设置,您会看到相同的内容,并且会在组末恢复。
这只会使您的所有定义成为全局的,因此它们在组外可用:
\documentclass[a4paper]{article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
% \time
\newcount\hour %
\newcount\hours %
\newcount\minutes %
\hour=\time \divide\hour by 60
\minutes=\time
\hours=\hour \multiply\hours by 60
\advance \minutes by -\hours
%end \time
%begin definitions of caldate
\newcount\fromcalyear %%
\newcount\fromcalmonth %%
\newcount\fromcalday %%
\newcount\fromcalhour %%
\newcount\fromcalminutes %%
\newcount\tocalyear %%
\newcount\tocalmonth %%
\newcount\tocalday %%
\newcount\tocalhour %%
\newcount\tocalminutes %%
\def\fromcaldate[#1-#2-#3 #4:#5]{%
\global\fromcalyear=#1 %
\global\fromcalmonth=#2 %
\global\fromcalday=#3 %
\global\fromcalhour=#4 %
\global\fromcalminutes=#5 %
\ \the\fromcalyear-\ifnum\fromcalmonth<10
0\fi\the\fromcalmonth-\ifnum\fromcalday<10
0\fi\the\fromcalday\ \ifnum\fromcalhour<10
0\fi\the\fromcalhour:\ifnum\fromcalminutes<10 0\fi\the\fromcalminutes
\vskip0.1\baselineskip}%
\def\tocaldate[#1-#2-#3 #4:#5]{%
\global\tocalyear=#1 %
\global\tocalmonth=#2 %
\global\tocalday=#3 %
\global\tocalhour=#4 %
\global\tocalminutes=#5\ %
\the\tocalyear-\ifnum\tocalmonth<10
0\fi\the\tocalmonth-\ifnum\tocalday<10
0\fi\the\tocalday\ \ifnum\tocalhour<10
0\fi\the\tocalhour:\ifnum\tocalminutes<10 0\fi\the\tocalminutes
\global\advance\fromcalyear by -\tocalyear\multiply\fromcalyear by
-1 %
\advance\fromcalmonth by -\tocalmonth\multiply \fromcalmonth
by-1 %
\global\advance\fromcalday by -\tocalday \multiply \fromcalday by-1 %
\global\advance\fromcalhour by -\tocalhour \multiply \fromcalhour by-1 %
\global\advance\fromcalminutes by -\tocalminutes \multiply \fromcalminutes by-1 %
\vskip0.1\baselineskip}%
\gdef\rescaldatetime{(\the\fromcalyear)-(\the\fromcalmonth)-(\the\fromcalday) (\the\fromcalhour):(\the\fromcalminutes)}
\gdef\rescaldate{(\the\fromcalyear)-(\the\fromcalmonth)-(\the\fromcalday)}
\gdef\rescaltime{(\the\fromcalhour):(\the\fromcalminutes)}
\begin{document}
\begin{longtable}{p{3cm}p{3cm}p{3cm}}
\fromcaldate[2013-01-01 13:00]
\tocaldate[2014-02-04 14:11]
\rescaldatetime\\
\\
\fromcaldate[2013-01-01 13:00]&
\tocaldate[2014-02-04 14:11]&
\rescaldatetime\\
&&
\rescaldatetime\\
\end{longtable}
\end{document}
答案2
我是这样解决的,的格式\rescaldatetime
留给用户,给出了一个例子。请仔细考虑\fromcaldate
和\tocaldate
和的使用\rescaldatetime
。
(这是 TeX 代码!)
%transformations of \time
\newcount\hour %
\newcount\hours %
\newcount\minutes %
\hour=\time \divide\hour by 60
\minutes=\time
\hours=\hour \multiply\hours by 60
\advance \minutes by -\hours
%end transformations of \time
%begin definitions of caldate
\newcount\fromcalyear %%
\newcount\fromcalmonth %%
\newcount\fromcalday %%
\newcount\fromcalhour %%
\newcount\fromcalminutes %%
\newcount\tocalyear %%
\newcount\tocalmonth %%
\newcount\tocalday %%
\newcount\tocalhour %%
\newcount\tocalminutes %%
\newcount\rescalyear %%
\newcount\rescalmonth %%
\newcount\rescalday %%
\newcount\rescalhour %%
\newcount\rescalminutes %%
\def\fromcaldate[#1-#2-#3 #4:#5]{%
\global\fromcalyear=#1 %
\global\fromcalmonth=#2 %
\global\fromcalday=#3 %
\global\fromcalhour=#4 %
\global\fromcalminutes=#5 %
\ \the\fromcalyear-\ifnum\fromcalmonth<10
0\fi\the\fromcalmonth-\ifnum\fromcalday<10
0\fi\the\fromcalday\ \ifnum\fromcalhour<10
0\fi\the\fromcalhour:\ifnum\fromcalminutes<10 0\fi\the\fromcalminutes
\vskip0.1\baselineskip}%
\def\tocaldate[#1-#2-#3 #4:#5]{%
\global\tocalyear=#1 %
\global\tocalmonth=#2 %
\global\tocalday=#3 %
\global\tocalhour=#4 %
\global\tocalminutes=#5\ %
\the\tocalyear-\ifnum\tocalmonth<10
0\fi\the\tocalmonth-\ifnum\tocalday<10
0\fi\the\tocalday\ \ifnum\tocalhour<10
0\fi\the\tocalhour:\ifnum\tocalminutes<10 0\fi\the\tocalminutes}
\def\rescaldate{
\global\rescalyear=\the\fromcalyear %
\global\rescalmonth=\fromcalmonth %
\global\rescalday=\fromcalday %
\global\rescalhour=\fromcalhour %
\global\rescalminutes=\fromcalminutes %
\advance\rescalyear by -\tocalyear %
\global\advance\rescalmonth by -\tocalmonth %
\global\advance\rescalday by -\tocalday %
\global\advance\rescalhour by -\tocalhour %
\global\advance\rescalminutes by -\tocalminutes %
\vskip0.1\baselineskip}%
\def\rescaldatetime{\rescaldate (\the\rescalyear)-(\the\rescalmonth)-(\the\rescalday)\ (\the\rescalhour):(\the\rescalminutes)}
%end definitions of caldate
Fromdate: \fromcaldate[2014-12-02 13:00]
Todate: \tocaldate[2012-11-05 04:16]
Resdate: \rescaldatetime
\def\rescaldatetime{{\bf Example}
\rescaldate
\ifnum\rescalyear>0 Years gone by \else Years to go \multiply\rescalyear by-1 \fi : (\the\rescalyear)
\ifnum\rescalmonth>0 Months gone by \else Months to go \multiply\rescalmonth by-1\fi :
(\the\rescalmonth)
\ifnum\rescalday>0 Days gone by \else Days to go \multiply\rescalday by-1\fi :
(\the\rescalday)
\ifnum\rescalhour>0 Hours gone by \else Hours to go \multiply\rescalhour by-1\fi :
(\the\rescalhour)
\ifnum\rescalminutes>0 Minutes gone by \else Minutes to go \multiply\rescalminutes by-1\fi :
(\the\rescalminutes)
}
\rescaldatetime
\bye