说明考试题目的分项数

说明考试题目的分项数

我正在尝试重构一些考试题目以使用该exam课程。大多数时候,我的问题在parts环境中被分解成几个部分。例如:

\documentclass[11pt,leqno,noanswers]{exam}
% Some styling stuff
\begin{document}
\addpoints
\begin{questions}

\titledquestion{A really tricky topic}
\begin{parts}
\part[4] How many wibbles are in a wobbit?
\part[1] Did you just make that up?
\part[2] Are you lying?
\part[1] Sure?
\part[1] Would you like to have a degree?
\end{parts}

% ... more questions ...
\end{questions}
\end{document}

对于这样的问题,在问题开始附近有一个类似的陈述是很标准的:

本题由 \underline{五} (5) 个部分组成 ((a)---(e))

其中数字(“五”)表示当前问题环境中部分的数量parts,字母(“a”和“e”)分别表示该环境中的第一个部分和最后一个部分。

这似乎已经为自动化做好了准备,但目前我对 (La)TeX 还不够熟悉。有什么建议吗?

答案1

考试课程没有提供此功能,但这里有一些快速代码可以满足您的要求。由于您似乎想多次说明零件数量,因此我创建了一个命令\setcountertopartsofq{number},将计数器设置numpofq为问题编号中的零件数量number

对于每个问题的每个部分,考试类都会定义一个控制序列,该序列扩展到该部分出现的页码。例如,对于问题 3 的第 2 部分,它创建\csname Pg@part@3@2\endcsname,因此要找到问题的最大部分编号,我们只需找到已定义此类控制序列的最大部分编号。

下面是一个完整的 LaTeX 文件,演示了这一点:

\documentclass[12pt,addpoints]{exam}

%--------------------------------------------------------------------
\newcounter{numpofq}

% The argument to \numpartsofquestion should be an arabic number that
% is the number of a question.  We set the counter numpofq to the
% number of parts of question number argument.
\newcommand{\setcountertopartsofq}[1]{%
  \def\qnotemp{#1}%
  \setcounter{numpofq}{1}%
  % We go to \numpofqrelay to increment numpofq until we find
  % a part number that doesn't exist:
  \numpofqrelay
}% setcountertopartsofq

\def\numpofqrelay{%
  \expandafter\ifx\csname Pg@part@\qnotemp
                  @\arabic{numpofq}\endcsname\relax
    % This part number doesn't exist; back up one and exit:
    \addtocounter{numpofq}{-1}%
    \let\nextnumpofqrelay=\relax
  \else
    % This part number exists; try the next number:
    \addtocounter{numpofq}{1}%
    \let\nextnumpofqrelay=\numpofqrelay
  \fi
  \nextnumpofqrelay
}% numpofqrelay

\makeatletter
\def\wordnum#1{\expandafter\word\csname c@#1\endcsname}
\def\word#1{%
  \ifcase #1 zero\or one\or two\or three\or four\or five\or six\or
  seven\or eight\or nine\or ten\or eleven\or twelve\or thirteen\or
  fourteen\or fifteen\or sixteen\or seventeen\or eighteen\or
  nineteen\or twenty\else too many\fi
}% word
\makeatother
%--------------------------------------------------------------------

\begin{document}

\begin{questions}
  \question This question has\setcountertopartsofq{\arabic{question}}
  \underline{\wordnum{numpofq}} (\arabic{numpofq}) parts,
  ((a)---(\alph{numpofq})).
  \begin{parts}
    \part Why are we here?

    \part Where should we be?

    \part Why aren't they here?
  \end{parts}

  \question This question, on the other hand,
  has\setcountertopartsofq{\arabic{question}}
  \underline{\wordnum{numpofq}} (\arabic{numpofq}) parts,
  ((a)---(\alph{numpofq})).
  \begin{parts}
    \part Where have all the flowers gone?

    \part Why do fools fall in love?
  \end{parts}

  \question This question has\setcountertopartsofq{\arabic{question}}
  \underline{\wordnum{numpofq}} (\arabic{numpofq}) parts,
  ((a)---(\alph{numpofq})).
  \begin{parts}
    \part Why?

    \part Why not?

    \part Who am I to say?

    \part What did I say?
  \end{parts}
\end{questions}
\end{document}

该命令\wordnum{countername}生成计数器值的单词countername。它最多可处理 20 个值,但您可以轻松扩展该值。 在此处输入图片描述

相关内容