在多项选择中将选项设为水平而不是垂直

在多项选择中将选项设为水平而不是垂直

我想输入一些多项选择题。我有以下代码。问题是,在某些问题中,我需要将选项放在一行中并均匀分布,而在某些问题中,我需要将两个选项放在一行中并均匀分布。我该怎么做呢?我知道有一些与此相关的答案,但我试图从中找出如何更改此代码,但每次我都会收到错误,我不想使用完全不同的代码。如果我能够在此代码中做到这一点,那就太好了。

我在这里先向您的帮助表示感谢。

\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 0 em}%
       \def\choice{%
         \item
       } % choice
       \labelwidth\leftmargin\advance\labelwidth-\labelsep
       \topsep=0pt
       \partopsep=0pt
     }%
  }%
  {\endlist}
%--------------------------------------------------------------------------------
\def\CChoice{%
      \choice
      \addanswer{\theenumi}{\thechoice}%
    }
    \let\CChoice\CChoice
%    \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
    \CChoice Ringo
  \end{choices}
\item What was the color of George Washinton's white horse?
  \begin{choices}
    \choice Green
    \CChoice Yellow
    \choice White
    \choice Socrates    
  \end{choices}
\item What was the color of George Washinton's white horse?
  \begin{choices}
    \choice Green
    \choice Yellow
    \CChoice White
    \choice Socrates
  \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
  \end{choices}
\item What was the color of George Washinton's white horse?

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

\showanswers
\end{document}

输出如下

答案1

问题:我们创建一个多列环境:

\makeatletter
\newenvironment{multichoices}[1][2]{%
\begin{multicols}{#1}}{%
\end{multicols}}
\makeatother

并在环境中使用它choices。MWE:

\documentclass{article}
\usepackage{multicol}
%--------------------------------------------------------------------
%--------------------------------------------------------------------
\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 0 em}%
       \def\choice{%
         \item
       } % choice
       \labelwidth\leftmargin\advance\labelwidth-\labelsep
       \topsep=0pt
       \partopsep=0pt
     }%
  }%
  {\endlist}
%--------------------------------------------------------------------------------
\def\CChoice{%
      \choice
      \addanswer{\theenumi}{\thechoice}%
    }
    \let\CChoice\CChoice
%    \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
}

\makeatletter
\newenvironment{multichoices}[1][2]{%
\begin{multicols}{#1}}{%
\end{multicols}}
\makeatother

%--------------------------------------------------------------------
\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}
   \begin{multichoices}[4]
    \choice George
    \choice Paul
    \choice John
    \CChoice Ringo
   \end{multichoices}
  \end{choices}
\item What was the color of George Washinton's white horse?
  \begin{choices}
   \begin{multichoices}[2]
    \choice Green
    \CChoice Yellow
    \choice White
    \choice Socrates    
   \end{multichoices}
  \end{choices}
\end{enumerate}
\end{document}

输出

顺便说一句:为什么不使用该exam课程?

相关内容