有人可以编辑这个以使其工作吗

有人可以编辑这个以使其工作吗
\documentclass{article}


%--------------------------------------------------------------------
%--------------------------------------------------------------------
\newcounter{choice}
\renewcommand\thechoice{\Alph{choice}}
\newcommand\choicelabel{\thechoice.}

%--------------------------------------------------------------------------------
\newenvironment{choices}%
  {\list{\choicelabel}%
     {\usecounter{choice}\def\makelabel##1{\hss\llap{##1}}%
       \settowidth{\leftmargin}{W.\hskip\labelsep\hskip 2.5em}%
       \def\choice{%
         \item
       } % choice
       \labelwidth\leftmargin\advance\labelwidth-\labelsep
       \topsep=0pt
       \partopsep=0pt
     }%
  }%
  {\endlist}
%--------------------------------------------------------------------------------
\def\CorrectChoice{%
      \choice
      \addanswer{\thequestion}{\thechoice}%
    }
    \let\correctchoice\CorrectChoice
%    \par % Uncomment this to have choices always start a new line
   % \let\par\@empty
    % If we're continuing the paragraph containing the question,
    % then leave a bit of space before the first choice:
    \ifvmode\else\enskip\fi
    \ignorespaces
  %
  {}
\makeatother
\newbox\allanswers
\setbox\allanswers=\hbox{}
\newcommand{\addanswer}[2]{%
  \global\setbox\allanswers=\hbox{\unhbox\allanswers \quad #1.~#2}%
}
\newcommand{\showanswers}{%
  \vfill
  \begin{center}
    Answers
  \end{center}
  \unhbox\allanswers
}





%--------------------------------------------------------------------
\begin{document}

\begin{enumerate}
\item One of these things is not like the others; one of these things
  is not the same.  Which one doesn't belong?
  \begin{choices}
    \choice George
    \choice Paul
    \choice John
    \correctchoice Ringo
    \choice Socrates
  \end{choices}
\item What was the color of George Washinton's white horse?
  \begin{choices}
    \choice Green
    \choice Yellow
    \choice White
  \end{choices}
\item One of these things is not like the others; one of these things
  is not the same.  Which one doesn't belong?
  \begin{choices}
    \choice George
    \choice Paul
    \choice John
    \choice Ringo
    \choice Socrates
  \end{choices}
\item What was the color of George Washinton's white horse?
  \begin{choices}
    \choice Green
    \choice Yellow
    \choice White
  \end{choices}
\item One of these things is not like the others; one of these things
  is not the same.  Which one doesn't belong?

  \begin{choices}
    \choice George
    \choice Paul
    \choice John
    \choice Ringo
    \choice Socrates
  \end{choices}
\item What was the color of George Washinton's white horse?

  \begin{choices}
    \choice Green
    \choice Yellow
    \choice White
  \end{choices}
\end{enumerate}

\showanswers
\end{document}

答案1

由于您使用标准对问题进行编号enumerate,因此您需要使用\theenumi而不是(由于未定义计数器,\thequestion因此会触发错误) ,因此您需要question\addanswer

\addanswer{\theenumi}{\thechoice}

完整示例:

\documentclass{article}


%--------------------------------------------------------------------
%--------------------------------------------------------------------
\newcounter{choice}
\renewcommand\thechoice{\Alph{choice}}
\newcommand\choicelabel{\thechoice.}

%--------------------------------------------------------------------------------
\newenvironment{choices}%
  {\list{\choicelabel}%
     {\usecounter{choice}\def\makelabel##1{\hss\llap{##1}}%
       \settowidth{\leftmargin}{W.\hskip\labelsep\hskip 2.5em}%
       \def\choice{%
         \item
       } % choice
       \labelwidth\leftmargin\advance\labelwidth-\labelsep
       \topsep=0pt
       \partopsep=0pt
     }%
  }%
  {\endlist}
%--------------------------------------------------------------------------------
\def\CorrectChoice{%
      \choice
      \addanswer{\theenumi}{\thechoice}%
    }
    \let\correctchoice\CorrectChoice
%    \par % Uncomment this to have choices always start a new line
   % \let\par\@empty
    % If we're continuing the paragraph containing the question,
    % then leave a bit of space before the first choice:
    \ifvmode\else\enskip\fi
    \ignorespaces
  %
  {}
\makeatother
\newbox\allanswers
\setbox\allanswers=\hbox{}
\newcommand{\addanswer}[2]{%
  \global\setbox\allanswers=\hbox{\unhbox\allanswers \quad #1.~#2}%
}
\newcommand{\showanswers}{%
  \vfill
  \begin{center}
    Answers
  \end{center}
  \unhbox\allanswers
}





%--------------------------------------------------------------------
\begin{document}

\begin{enumerate}
\item One of these things is not like the others; one of these things
  is not the same.  Which one doesn't belong?
  \begin{choices}
    \choice George
    \choice Paul
    \choice John
    \correctchoice Ringo
    \choice Socrates
  \end{choices}
\item What was the color of George Washinton's white horse?
  \begin{choices}
    \choice Green
    \correctchoice Yellow
    \choice White
  \end{choices}
\item One of these things is not like the others; one of these things
  is not the same.  Which one doesn't belong?
  \begin{choices}
    \choice George
    \choice Paul
    \choice John
    \choice Ringo
    \choice Socrates
  \end{choices}
\item What was the color of George Washinton's white horse?
  \begin{choices}
    \choice Green
    \choice Yellow
    \correctchoice White
  \end{choices}
\item One of these things is not like the others; one of these things
  is not the same.  Which one doesn't belong?

  \begin{choices}
    \choice George
    \choice Paul
    \choice John
    \choice Ringo
    \choice Socrates
  \end{choices}
\item What was the color of George Washinton's white horse?

  \begin{choices}
    \choice Green
    \choice Yellow
    \choice White
  \end{choices}
\end{enumerate}

\showanswers
\end{document}

在此处输入图片描述

我想知道你为什么不使用专门的课程(例如exam)或包(exsheets,例如),它为您提供您正在构建的功能以及许多其他可立即使用的功能。

相关内容