答案1
该包fmtcount
定义了命令\numberstring{counter}
。将其添加到将考试类中的计数器设置为基于第一组问题的计数,我们得到
\documentclass{exam}
\usepackage{totcount}
\usepackage{fmtcount}
\makeatletter
\newcommand{\extractcntrvalue}[1]{%
\value{#1@totc}%
}
\makeatother
\newtotcounter{s}
\setcounter{s}{0}
\newtotcounter{e}
\setcounter{e}{0}
\newcommand{\squestion}[0]{\stepcounter{s}\question}
\newcommand{\equestion}[0]{\stepcounter{e}\question}
\begin{document}
\fullwidth{\Large \textbf{Short questions}}
There are \total{s}\ short questions. %display the number of short questions.
\begin{questions}
\squestion
This is the first short question.
\squestion
This is the second short question.
\end{questions}
\fullwidth{\Large \textbf{Essay questions}}
There are \total{e}\ essay questions. %display the number of essay questions.
\begin{questions}
\setcounter{question}{\extractcntrvalue{s}} % Set the counter to start with 3
\equestion
This is the first essay question.
\equestion
This is the second essay question.
\equestion
This is the third essay question.
\equestion
This is the fourth essay question.
\end{questions}
For the record there is a total of \numberstring{question} questions.
\end{document}
请注意,如果您想从“总”计数器中提取信息,这将行不通,因为totcount
计数器不是 LaTeX 意义上的计数器。
但是,我们可以将上面定义的命令与命令\extractcntrvalue
一起使用:\numeberstringnum
\documentclass{exam}
\usepackage{totcount}
\usepackage{fmtcount}
\makeatletter
\newcommand{\extractcntrvalue}[1]{%
\value{#1@totc}%
}
\makeatother
\newtotcounter{s}
\setcounter{s}{0}
\newtotcounter{e}
\setcounter{e}{0}
\newcommand{\squestion}[0]{\stepcounter{s}\question}
\newcommand{\equestion}[0]{\stepcounter{e}\question}
\begin{document}
\fullwidth{\Large \textbf{Short questions}}
There are \numberstringnum{\extractcntrvalue{s}} short questions. %display the number of short questions.
\begin{questions}
\squestion
This is the first short question.
\squestion
This is the second short question.
\end{questions}
\fullwidth{\Large \textbf{Essay questions}}
There are \numberstringnum{\extractcntrvalue{e}} essay questions. %display the number of essay questions.
\begin{questions}
\setcounter{question}{\extractcntrvalue{s}} % Set the counter to start with 3
\equestion
This is the first essay question.
\equestion
This is the second essay question.
\equestion
This is the third essay question.
\equestion
This is the fourth essay question.
\end{questions}
For the record there is a total of \numberstring{question} questions.
\end{document}