我使用“日历”包为所教课程创建了教学大纲。表格中的一些条目突出显示了家庭作业和测验。
是否可以从日历中获取家庭作业和测验的日期,并将其用于另一个包含所有重要日期(家庭作业、测验、期中考试、期末考试等日期)的表格中?如果日历中测验和家庭作业的位置发生变化,重要日期表中的日期应自动更改。
我认为我们需要给测验和作业贴上标签,以便我们可以交叉引用它们。
这是代码。
\documentclass[10pt]{article}
%\usepackage[ a4paper]{geometry}
\textwidth=7in
\textheight=9.5in
\topmargin=-1in
\headheight=0in
\headsep=.5in
\hoffset -.85in
\usepackage{enumitem}
\usepackage{termcal}
\usepackage{hyperref}
\hypersetup{colorlinks= true, allcolors= blue}
\newcommand{\MWClass}{
\calday[\bf Monday]{\classday}
\skipday
\calday[\bf Wednesday]{\classday}
\skipday
\skipday\skipday
\skipday
}
\setlist[itemize]{itemsep=1pt, topsep=0pt}
\setlist[enumerate]{itemsep=1pt, topsep=0pt}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\begin{document}
\begin{center}
\begin{calendar}{01/11/2021}{2}
\setlength{\calboxdepth}{0.6in}
\MWClass
\caltexton{1}{\vspace{1ex} Course Introduction}
\caltextnext{
\vspace{1ex}
Lecture 1 \\ \vspace{1ex}
{\bf Chapter 9: Steady-State Power Analysis} \vspace{1ex}
\begin{itemize}
\item[] {\bf Sec 9.1} Instantaneous power
\end{itemize}}
\caltexton{1}{}
\caltextnext{\vspace{1.5ex}
{\bf \color{red} HW 1 (Chapter 9)}}
\caltextnext{\vspace{1.5ex}
{\bf \color{red} Quiz 1 (Chapter 9)}}
\end{calendar}
\end{center}
\begin{center}
{\Large Important Dates}\\ \vspace{-1ex}
\end{center}
\begingroup
\normalsize
\renewcommand{\arraystretch}{2}
\centering
\begin{longtable}{|l|p{0.15\textwidth}|l|}
\hline
& \bfseries Chapter & \bfseries Due Date \\ \hline \endhead
HW 1 & Ch 9 & Date of HW 1 in the Clanedar\\ \hline
Quiz 1 & Ch 9 & Date of Quiz 1 in the Clanedar\\ \hline
\end{longtable}
\endgroup
\clearpage
\newpage
\end{document}
答案1
这可以使用etoolbox
包中的列表处理宏来完成。这个想法是定义一个新命令,显示日历中的重要事件,但也将信息(名称、章节、日期)存储在列表中。然后,在日历完成后,您可以循环列表longtable
以显示项目。
etoolbox
调用来自的列表处理宏,list[type]add
其中类型表示在列表中存储信息的方式。在下面的代码中\listxadd
使用,这意味着扩展和全局。需要扩展是因为日期值必须存储为原始数字,而不是随着日历天数不断变化而变化的宏,而全局是因为表中日历之外需要这些值。这些值作为表行存储在列表中,即name & chapter & date
。
更新:您可以通过在日历中的相应位置插入额外命令来手动向表中添加行\listadd
。在这种情况下,使用\listgadd
(添加全局没有扩展)因为这允许在添加的内容类型方面具有更大的灵活性。例如,\multicolumn
不允许使用命令,\listxadd
因为多列的立即扩展会干扰列表处理。请注意,必须添加额外的行里面 \caltextnext
或\caltexton
,因为否则行会在最后添加。
\listxadd
可以通过修改内的参数来调整表格行的格式\importantitem
,例如添加用于备注的额外参数或包括年份。
处理过程包括定义循环函数\do
,该函数需要在表格外部完成,并使用对列表的所有元素调用此函数\dolistloop
。该\do
函数包含\\\hline
,即它完成表格行。
另一个问题是将日期打印为序数,例如第11届或者第三。该termcal
包有一个宏(\ordinaldate
),但该宏会导致 的列表处理内部出现错误etoolbox
。因此,复制了包的一小部分nth
来生成序数后缀。
代码:
\documentclass[10pt]{article}
\usepackage{etoolbox}
%\usepackage[ a4paper]{geometry}
\textwidth=7in
\textheight=9.5in
\topmargin=-1in
\headheight=0in
\headsep=.5in
\hoffset -.85in
% copied from nth.sty version 2002/27/02 Donald Arseneau
\def\nth#1{%
#1\expandafter \nthSuff \expandafter 0\number\ifnum #1<0-\fi#1\delimiter%
}
\def\nthSuff#1#2#3{%
\ifx \delimiter#3% #1#2 are last two digits
\ifnum #1=1 th% teens are always ``th''
\else % use appropriate suffix
\ifcase #2 th\or st\or nd\or rd\else th\fi
\fi
\else % continue scanning for last two digits
\expandafter \nthSuff \expandafter #2\expandafter #3%
\fi}
% end of copied nth code
\usepackage{enumitem}
\usepackage{termcal}
\usepackage{hyperref}
\hypersetup{colorlinks= true, allcolors= blue}
% arguments: #1=name, #2=chapter, #3=remarks
\newcommand{\importantitem}[3]{%
\textbf{\textcolor{red}{#1 (Chapter #2)}}%
%Weekday, Day Month, Year + {Some Custom Text}
\listxadd{\impitems}{#1 & Ch #2 & \nth{\thedate}\ \monthname, \theyear\ #3}
}
\newcommand{\MWClass}{
\calday[\bf Monday]{\classday}
\skipday
\calday[\bf Wednesday]{\classday}
\skipday
\skipday\skipday
\skipday
}
\setlist[itemize]{itemsep=1pt, topsep=0pt}
\setlist[enumerate]{itemsep=1pt, topsep=0pt}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\begin{document}
\begin{center}
\begin{calendar}{01/11/2021}{2}
\setlength{\calboxdepth}{0.6in}
\MWClass
\caltexton{1}{\vspace{1ex} Course Introduction}
\caltextnext{
\vspace{1ex}
Lecture 1 \\ \vspace{1ex}
{\bf Chapter 9: Steady-State Power Analysis} \vspace{1ex}
\begin{itemize}
\item[] {\bf Sec 9.1} Instantaneous power
\end{itemize}}
\caltexton{1}{}
\caltextnext{\vspace{1.5ex}
\importantitem{HW 1}{9}{at 11:59 PM (Online submission)}%
\listgadd{\impitems}{\multicolumn{3}{|l|}{\textit{Late submissions will not be graded}}}%
}
\caltextnext{\vspace{1.5ex}\arabic{textdaycount}
\importantitem{Quiz 1}{9}{at 11:59 PM (Online submission)}%
\listgadd{\impitems}{Office hour & all chapters & Every Monday 10:00h}%
}
\end{calendar}
\end{center}
\begin{center}
{\Large Important Dates}\\ \vspace{-1ex}
\end{center}
\begingroup
\normalsize
\renewcommand{\arraystretch}{2}
\centering
\renewcommand*{\do}[1]{#1\\\hline} % define item processing macro
\begin{longtable}{|l|p{0.15\textwidth}|l|}
\hline
& \bfseries Chapter & \bfseries Due Date \\ \hline \endhead
\dolistloop{\impitems} % loop the list to generate table rows
\end{longtable}
\endgroup
\end{document}
结果:
更新内容:
答案2
使用 LaTeX 2ε 内核的\@starttoc
/\addtocontents
机制,您可以定义一个命令
\ImportantDate{⟨WorkAssignment⟩}{⟨chapter-number⟩}{⟨customary text⟩}
⟨工作任务⟩= 家庭作业 1 或测验 3
⟨章节编号⟩= 章节数
⟨习惯文字⟩= 习惯文本
哪个
- 交付: %
⟨WorkAssignment⟩~(Chapter~⟨chapter-number⟩)
- via为文件
\addtocontents
创建一个条目 (loids =\@writefile
\jobname.loids
升是oF我重要d吃s) 表示调用带有参数的宏,该参数\LineWithImportantDate
包含创建 longtable 的另一行所需的所有信息。
\listofImportantDates
然后您可以拥有一个类似于\tableofcontents
—via的宏,它\@starttoc
导入 .loids 文件并 \write
为 .loids 文件创建 -handle。
您可以使用\AtBeginDocument
(来自 LaTeX 2ε 内核)和\AfterLastShipout
(来自包尽头) 用于将 longtable-preamble/postamble 添加/添加到 .loids 文件前面或后面。
您需要重新定义\calprintdate
以便\hypertarget
创建一个。
您可以使用包的宏datetime2
- 用于计算星期几
- 获取星期几的名称
- 获取月份名称
- 以序数形式获取月份中的日期(附加st、nd、rd、th)。
您可以定义命令\Homework
和\Quiz
步骤计数器“家庭作业”相应的“测验”,然后调用,将剩余参数的收集留给。\ImportantDate{⟨WorkAssignment⟩}
\ImportantDate
语法与自动生成的\ImportantDate
相同:⟨WorkAssignment⟩
\Homework{⟨chapter-number⟩}{⟨customary text⟩}
\Quiz{⟨chapter-number⟩}{⟨customary text⟩}
这些命令的星号变体不会从重要日期列表生成到日历的超链接。
编辑1:与稍旧的 LaTeX 2ε 内核一样,\@writefile
-mechanism 没有考虑到这一点,我从代码中\protected@file@percent
删除了所有实例。\protected@file@percent
代码(保存为测试.tex) 在 Debian Buster x86 下使用 TeXLive 2020 成功编译。我必须编译四次而不删除中间的辅助文件,直到来自 latex 运行期间创建/更改的辅助文件的所有内容(longtable、hypertargets)都正确匹配。
编辑2:我添加了一个命令
\ImportantDateNote{⟨amount of empty cells at the left of the cell with the note (range from 0 to 2)⟩}%
{⟨amount of cells the note shall span (range from 1 to 3)⟩}%
{⟨flag <=0 or >0 denoting if vertical bar shall be drawn between two consecutive empty cells⟩}%
{⟨alignmant of note l r c p{0.15\textwidth}⟩}%
{⟨text of note⟩}
用于将所有注释放入重要日期的表中。
该表有三列,因此总和 ⟨带有注释的单元格左侧的空单元格数量(范围从 0 到 2)⟩ 和 ⟨注释应跨越的单元格数量(范围从 1 到 3)⟩不得超过值 3。
\documentclass[10pt]{article}
%\usepackage[a4paper]{geometry}
\textwidth=7in
\textheight=9.5in
\topmargin=-1in
\headheight=0in
\headsep=.5in
\hoffset -.85in
\usepackage{enumitem}
\usepackage{termcal}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{colorlinks=true, allcolors= blue}
\newcommand{\MWClass}{%%%
\calday[\bf Monday]{\classday}%%%
\skipday
\calday[\bf Wednesday]{\classday}%%%
\skipday
\skipday\skipday
\skipday
}
\setlist[itemize]{itemsep=1pt, topsep=0pt}
\setlist[enumerate]{itemsep=1pt, topsep=0pt}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
%////////////////////////////////////////////////////////////////////////////
\usepackage[calc, en-GB-numeric]{datetime2}
\usepackage{atveryend}
\DTMlangsetup[en-GB]{ord=raise}
\makeatletter
\newcommand*\ImportantDate@Chaptername{Chapter}%
\newcommand*\ImportantDate@AbbreviatedChaptername{Chapter}%
\newcommand\ImportantDateTempa{}%
\@ifdefinable\ImportantDate{%
\DeclareRobustCommand\ImportantDate{%
\@ifstar{\@ImportantDate*}{\@ImportantDate{}}%
}%
}%
\newcommand\@ImportantDate[4]{%
% #1 - Star/NoStar
% #2 - WorkAssignment - e.g., HW1 or Quiz 1
% #3 - number of chapter
% #4 - customary text
#2 (\ImportantDate@Chaptername~#3)%
\begingroup
\DTMsavenoparsedate{storeddate}{\arabic{year}}{\arabic{month}}{\arabic{date}}{-1}%
\DTMcomputedayofweekindex{\DTMfetchyear{storeddate}-\DTMfetchmonth{storeddate}-\DTMfetchday{storeddate}}{\ImportantDateTempa}%
\addtocontents{loids}{%
\string\LineWithImportantDate#1\@percentchar^^J%
\space\space{\detokenize{#2}}\@percentchar^^J%
\space\space{\detokenize{#3}}\@percentchar^^J%
\space\space{\detokenize{#4}}\@percentchar^^J%
\space\space{\arabic{year}}\@percentchar^^J%
\space\space{\arabic{month}}\@percentchar^^J%
\space\space{\arabic{date}}\@percentchar^^J%
\space\space{\ImportantDateTempa}\@percentchar^^J%
\space\space{caldate.\arabic{year}-\arabic{month}-\arabic{date}}^^J%
}%
\endgroup
}%
\@ifdefinable\LineWithImportantDate{%
\DeclareRobustCommand\LineWithImportantDate{%
\@ifstar{\@LineWithImportantDate{\@secondoftwo}}{\@LineWithImportantDate{\hyperlink}}%
}%
}%
\newcommand\@LineWithImportantDate[9]{%
#1{#9}{#2}&%
#1{#9}{\ImportantDate@AbbreviatedChaptername~#3}&%
#1{#9}{%
\DTMWeekdayname{#8}, \DTMordinal{#7}~\DTMMonthname{#6}, #5#4%
}%
\\\hline
}%
\newcommand\ImportantDateNote[5]{%
% #1 - amount of empty cells at the left of the cell with the note
% #2 - amount of cells the note shall span
% #3 - flag <=0/>0 denoting if vertical bar between 2 consecutive empty cells
% #4 - alignmant of note l r c p{0.15\textwidth}
% #5 - text of note
\@bsphack
\addtocontents{loids}{\string\LineWithImportantNote{#1}{#2}{#3}{#4}{#5}}%
\@esphack
}%
\newcommand\LineWithImportantNote[5]{%
\ifnum#1>0 \exchange{%
\ifnum #3>0 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\ifnum#1>1 \expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi
}{\@firstoftwo}%
{\multicolumn{#1}{|l}{}&}%
{\multicolumn{1}{|l}{}&\multicolumn{1}{|l}{}&}%
}\fi
\multicolumn{#2}{|#4|}{#5}%
\ifnum\number\numexpr3-#1-#2\relax>0 \exchange{%
\ifnum #3>0 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\ifnum\number\numexpr3-#1-#2\relax>1 \expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi
}{\@firstoftwo}%
{&\multicolumn{\numexpr3-#1-#2\relax}{l|}{}}%
{&\multicolumn{1}{l|}{}&\multicolumn{1}{l|}{}}%
}\fi
\\\hline
}%
\newcounter{quizzes}%
\newcounter{homeworks}%
\newcommand\homeworksname{Homework}%
\newcommand\quizzesname{Quiz}%
\@ifdefinable\Stopromannumeral{\chardef\Stopromannumeral=`\^^00}%
\newcommand\exchange[2]{#2#1}%
\@ifdefinable\Homework{%
\DeclareRobustCommand\Homework{%
\@ifstar{\@Homework{\expandafter*}}{\@Homework{}}%
}%
}%
\newcommand\@Homework[1]{%
\stepcounter{homeworks}%
\expandafter\ImportantDate#1\expandafter{%
\romannumeral
\expandafter\exchange\expandafter
{\number\value{homeworks}}%
{\expandafter\Stopromannumeral\homeworksname~}%
}%
}%
\@ifdefinable\Quiz{%
\DeclareRobustCommand\Quiz{%
\@ifstar{\@Quiz{\expandafter*}}{\@Quiz{}}%
}%
}%
\newcommand\@Quiz[1]{%
\stepcounter{quizzes}%
\expandafter\ImportantDate#1\expandafter{%
\romannumeral
\expandafter\exchange\expandafter
{\number\value{quizzes}}%
{\expandafter\Stopromannumeral\quizzesname~}%
}%
}%
\renewcommand\calprintdate{%
\hbox{%
\Hy@raisedlink{%
\hypertarget{%
caldate.\arabic{year}-\arabic{month}-\arabic{date}%
}{}%
}%
% You can change this to do some more sophisticated/more beautiful things.
\ifnewmonth\framebox{\monthname\ \ordinaldate}%
\else \ordinaldate\fi
}%
}%
\AtBeginDocument{%
\addtocontents{loids}{\string\begingroup}%
\addtocontents{loids}{\string\renewcommand{\string\arraystretch}{2}}%
\addtocontents{loids}{\string\begin{longtable}{|l|p{0.15\string\textwidth}|l|}}%
\addtocontents{loids}{\string\hline}%
\addtocontents{loids}{%
&\string\bfseries\space Chapter&\string\bfseries\space Due Date\string\\ \string\hline\space \string\endhead
}%
}%
\AfterLastShipout{%
\begingroup
\let\writecopy=\write
\def\write{\noexpand\immediate\noexpand\writecopy}%
\addtocontents{loids}{\string\end{longtable}}%
\addtocontents{loids}{\string\endgroup}%
\endgroup
}%
\newcommand\listofImportantDates{%
\IfFileExists{\jobname.loids}{%
\par
\begingroup
\centering
{\Large Important Dates}\\ \vspace{-1ex} %
\par
\@starttoc{loids}%
\par
\endgroup
}{%
\@starttoc{loids}%
}%
}%
\makeatother
%////////////////////////////////////////////////////////////////////////////
\begin{document}
\listofImportantDates
\clearpage
\newpage
\begin{center}
\begin{calendar}{01/11/2021}{2}
\setlength{\calboxdepth}{0.6in}
\MWClass
\caltexton{1}{\vspace{1ex} Course Introduction}%
\caltextnext{%
\vspace{1ex} %
Lecture 1 \\ \vspace{1ex}
{\bf Chapter 9: Steady-State Power Analysis}%
\vspace{1ex}%
\begin{itemize}
\item[] {\bf Sec 9.1} Instantaneous power%
\end{itemize}%
}
\caltexton{1}{}%
\caltextnext{%
\vspace{1.5ex}%
{\bf\color{red}\Homework{9}{ at 11:59 PM (Online submission)}}%
\ImportantDateNote{1}{2}{0}{c}{\emph{The sooner you do your homework, the sooner it will stop weighing your mind!}}%
}%
\caltextnext{%
\vspace{1.5ex}%
{\bf\color{red}\Quiz*{9}{ at 11:59 PM (Offline omission)}}%
\ImportantDateNote{0}{1}{1}{l}{\emph{A note.}}%
\ImportantDateNote{1}{1}{0}{l}{\emph{A note.}}%
\ImportantDateNote{2}{1}{1}{l}{\emph{A note.}}%
\ImportantDateNote{2}{1}{0}{l}{\emph{A note.}}%
\ImportantDateNote{0}{2}{0}{l}{\emph{A note.}}%
\ImportantDateNote{0}{3}{0}{l}{\emph{A note.}}%
\ImportantDateNote{1}{2}{0}{l}{\emph{A note.}}%
\ImportantDateNote{0}{1}{0}{l}{\emph{A note.}}%
}%
\end{calendar}
\end{center}
\end{document}