带显示答案的多项选择题

带显示答案的多项选择题

有人可以更改这些代码,choices以便选项垂直显示在一行中而不是一个段落中吗?

\documentclass{article}

%--------------------------------------------------------------------
\newcounter{question}
\newenvironment{questions}{%
  \list{\thequestion.}%
  {%
    \usecounter{question}%
    \def\question{\item}%
    \settowidth{\leftmargin}{10.\hskip\labelsep}%
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
  }%
}
{%
  \endlist
}%



\newcounter{choice}
\renewcommand\thechoice{\Alph{choice}}
\newcommand\choicelabel{\thechoice.}
%\makeatletter
\newenvironment{choices}%
  {%
    \setcounter{choice}{0}%
    \def\choice{%
      \refstepcounter{choice}%
      \ifnum\value{choice}>1\relax
        \penalty -50\hskip 1em plus 1em\relax
      \fi
      \choicelabel
      \nobreak\enskip
    }% choice


    \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{questions}
  \question What was the color of George Washington's white horse? 
  \begin{choices} 
    \choice Blue \\
    \choice Yellow \\
    \correctchoice White \\
    \choice Black
  \end{choices}
  \question Which of these things doesn't fit in?
  \begin{choices}
    \choice John
    \choice Paul 
    \choice George 
    \choice Ringo 
    \correctchoice Socrates
  \end{choices}
  \question Who's buried in Grant's tomb?
  \begin{choices}
    \choice Washington
    \choice Mickey Mouse
    \correctchoice Grant
  \end{choices}
\end{questions}

\showanswers
\newpage



\begin{questions}
  \question $1+1= \mathord{?}$
  \begin{choices}
    \choice $0$ \choice $1$ \correctchoice $2$ \choice $3$ \choice $4$
  \end{choices}
  \question $\sin \frac{\pi}{2} = \mathord{?}$
  \begin{choices}
    \choice $0$ \correctchoice $1$ \choice $2$ \choice $\frac{\pi}{2}$
  \end{choices}
  \question What was the color of the bus driver's eyes?
  \begin{choices}
    \choice Green \choice Yellow \correctchoice Blue \choice Red
  \end{choices}
\end{questions}

\showanswers

\end{document}

答案1

您可以在环境定义\par之前添加来实现您想要的(我在代码中用标记表示了变化):\choicelabelchoices%NEW

\documentclass{article}

%--------------------------------------------------------------------
\newcounter{question}
\newenvironment{questions}{%
  \list{\thequestion.}%
  {%
    \usecounter{question}%
    \def\question{\item}%
    \settowidth{\leftmargin}{10.\hskip\labelsep}%
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
  }%
}
{%
  \endlist
}%

\newcounter{choice}
\renewcommand\thechoice{\Alph{choice}}
\newcommand\choicelabel{\thechoice.}
%\makeatletter
\newenvironment{choices}%
  {%
    \setcounter{choice}{0}%
    \def\choice{%
      \refstepcounter{choice}%
      \ifnum\value{choice}>1\relax
        \penalty -50\hskip 1em plus 1em\relax
      \fi
      \par\choicelabel% NEW: \par added
      \nobreak\enskip
    }% choice


    \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{questions}
  \question What was the color of George Washington's white horse? 
  \begin{choices} 
    \choice Blue
    \choice Yellow
    \correctchoice White
    \choice Black
  \end{choices}
  \question Which of these things doesn't fit in?
  \begin{choices}
    \choice John
    \choice Paul 
    \choice George 
    \choice Ringo 
    \correctchoice Socrates
  \end{choices}
  \question Who's buried in Grant's tomb?
  \begin{choices}
    \choice Washington
    \choice Mickey Mouse
    \correctchoice Grant
  \end{choices}
\end{questions}

\showanswers
\newpage



\begin{questions}
  \question $1+1= \mathord{?}$
  \begin{choices}
    \choice $0$ \choice $1$ \correctchoice $2$ \choice $3$ \choice $4$
  \end{choices}
  \question $\sin \frac{\pi}{2} = \mathord{?}$
  \begin{choices}
    \choice $0$ \correctchoice $1$ \choice $2$ \choice $\frac{\pi}{2}$
  \end{choices}
  \question What was the color of the bus driver's eyes?
  \begin{choices}
    \choice Green \choice Yellow \correctchoice Blue \choice Red
  \end{choices}
\end{questions}

\showanswers

\end{document}

在此处输入图片描述

也许你可能对exam文档类或exsheets该软件包提供了可以立即使用的功能来构建考试。

相关内容