将数字转换为单词

将数字转换为单词

参考下面的问题 将考试类中的计数器设置为基于第一组问题的计数

我想修改一下这个答案。有一些\total{s}\简短的问题。

从有 2 个简短问题到有两个简短问题。

谢谢。

答案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}

在此处输入图片描述

相关内容