考试中的计数选择

考试中的计数选择

平均能量损失

\documentclass[11pt,paper=a4,answers]{exam}
\usepackage{environ}

\newtoks\allanswers

\NewEnviron{answer}
{%
 \edef\temp{%
   \the\allanswers % the previous ones
   \thequestion) \thechoice
   \noexpand\par % maybe \par has been redefined
   \unexpanded\expandafter{\BODY}%
 }
 \global\allanswers=\expandafter{\temp}
}

    \newcommand{\Cchoice}{\CorrectChoice\begin{answer}\end{answer}}
\newcommand{\showallanswers}{%
\ifprintanswers {\centering ANSWER KEYS \par} \textbf{\the\allanswers} \fi}

\begin{document}

\begin{questions}
\question One
\begin{choices}
\Cchoice True
\choice False
\choice False
\choice False
\choice False
\end{choices}

\question Two
\begin{choices}
\choice False
\choice False
\Cchoice True
\choice False
\choice False
\end{choices}
\end{questions}
\showallanswers
\end{document}

我想要输出,

在此处输入图片描述

也就是说,我想要所有真的选择计数。

选项 A 的数量

选择 B 的数量

选择 C ​​的数量

选择 D 的数量

选择项 E 的数量

是否可以?

答案1

使用etoolbox宏命令的算术:

\documentclass[11pt,paper=a4,answers]{exam}
\usepackage{ifthen}
\usepackage{etoolbox}
\usepackage{environ}

\newtoks\allanswers

\NewEnviron{answer}
{%
 \edef\temp{%
   \the\allanswers % the previous ones
   \thequestion) \thechoice
   \noexpand\par % maybe \par has been redefined
   \unexpanded\expandafter{\BODY}%
 }
 \global\allanswers=\expandafter{\temp}
 \csnumgdef{ctrchoice\thechoice}{\csname ctrchoice\thechoice\endcsname + 1} % Increments ctrchoice\thechoice if it is defined; sets it to one otherwise.
}

    \newcommand{\Cchoice}{\CorrectChoice\begin{answer}\end{answer}}
\newcommand{\showallanswers}{%
\ifprintanswers {\centering ANSWER KEYS \par} \textbf{\the\allanswers} \fi}


\newcommand{\showchoicecounts}[1]{% The argument is the number of choices
    \setcounter{choice}{0}
    \whiledo{\value{choice} < #1}{%
        \stepcounter{choice}%
        \csnumgdef{ctrchoice\thechoice}{\csname ctrchoice\thechoice\endcsname}% Set ctrchoice\thechoice to 0 if undefined
        % Edit the following line to do formatting
        \thechoice: \csname ctrchoice\thechoice\endcsname \newline}}

\begin{document}

\begin{questions}
\question One
\begin{choices}
\Cchoice True
\choice False
\choice False
\choice False
\choice False
\end{choices}

\question Two
\begin{choices}
\choice False
\choice False
\Cchoice True
\choice False
\choice False
\end{choices}
\end{questions}
\showallanswers


\showchoicecounts{5}
\end{document}

相关内容