考试类允许生成根据问题数量动态生成的成绩表,如下所示
\documentclass[addpoints,12pt]{exam}
\begin{document}
\multirowgradetable{1}[questions]
\begin{questions}
\question[10] First question
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\end{questions}
由于该表太宽,考试提供了显示多个表的选项:
\documentclass[addpoints,12pt]{exam}
\begin{document}
\multirowgradetable{2}[questions]
\begin{questions}
\question[10] First question
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\end{questions}
我希望表格数量能够动态生成,这样每 10 个练习就有一张表格。我使用计算器包尝试了这一点:
\documentclass[addpoints,12pt]{exam}
\usepackage{calculator}
\begin{document}
\begin{questions}
\question[10] First question
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\end{questions}
\INTEGERDIVISION{\numquestions}{10}{\sola}{\solb}
\ADD{\sola}{1}{\numrows}
\multirowgradetable{\numrows}[questions]
\end{document}
只要我将表格放在文档末尾,此方法即可。但我希望将其放在开头。我该怎么做才能实现此目的?
答案1
您可以在辅助文件中的结束文档中保存问题的数量,以便在下次运行开始时可以获得该数量。
如果问题数量达到八个,则生成一个表格,否则生成两个表格。
\documentclass[addpoints,12pt]{exam}
\makeatletter
\AtEndDocument{%
\ifdefined\exam@numquestions
\immediate\write\@auxout{\string\total@questions{\exam@numquestions}}%
\fi
}
\newcommand{\total@questions}[1]{\gdef\totalquestions{#1}}
\providecommand{\totalquestions}{1}
\makeatother
\begin{document}
\multirowgradetable{%
\ifnum\totalquestions<9 1\else 2\fi
}[questions]
\begin{questions}
\question[10] First question
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\question[10] Another
\end{questions}
\end{document}
这是仅提供八个问题时的输出。