如何用 LaTeX 编写多项选择题试卷?

如何用 LaTeX 编写多项选择题试卷?

我想写一本包含许多多项选择题试卷的书。将下面的代码放入我的序言中,我写了如下问题:

\begin{enumerate}
\item $2+2=?$
\choice $1$   \choice $2$  \choice $3$   \choice $4$   \choice $5$
\end{enumerate}

对于每张试卷,我想在页脚中创建一个正确答案表。有没有简单的方法可以做到这一点,或者有没有 LaTeX 宏脚本可以通过在其 LaTeX 代码中提及正确答案来自动执行此操作?例如;

\choice 1 \choice 2 \choice 3 \correctchoice 4 \choice 5

另外,由于选项不是并排的,我损失了很多空间。有没有 LaTeX 代码可以更对称地自动将选项写在一行或两行中?

%%% Codes in preamble %%%

\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 1.5em}% \def\choice{% \item } % choice \labelwidth\leftmargin\advance\labelwidth-\labelsep \topsep=0pt \partopsep=0pt }% }%
{\endlist}

\newenvironment{oneparchoices}%    
{% \setcounter{choice}{0}% \def\choice{% \refstepcounter{choice}% \ifnum\value{choice}>1\relax \penalty -50\hskip 1em plus 1em\relax \fi \choicelabel \nobreak\enskip }% choice % If we're continuing the paragraph containing the question, %then leave a bit of space before the first choice:

\ifvmode\else\enskip\fi
\ignorespaces
}%

答案1

以下是我之前的回答在这个版本中,选择不属于任何环境;你只需在问题后开始列出\choices 和s。\correctchoice

这是一个完整的 LaTeX 文件,可以说明这一点。

\documentclass{article}

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

\newcounter{choice}
\renewcommand\thechoice{\Alph{choice}}
\newcommand\choicelabel{\thechoice.}
\def\choice{%
  \ifinchoices
    % Do nothing
  \else
    \startchoices
  \fi
  \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

\newcommand{\startchoices}{%
  \inchoicestrue
  \setcounter{choice}{0}%
% \par % Uncomment this to have choices always start a new line
  % If we're continuing the paragraph containing the question,
  % then leave a bit of space before the first choice:
  \ifvmode\else\enskip\fi
}%

\newbox\allanswers
\setbox\allanswers=\hbox{}
\newcommand{\addanswer}[2]{%
  \global\setbox\allanswers=\hbox{\unhbox\allanswers #1.~#2\quad}%
}
\newcommand{\showanswers}{%
  \vfill
  \begin{center}
    Answers
  \end{center}
  \noindent\unhbox\allanswers
}



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


\begin{questions}
  \question What was the color of George Washington's white horse?
      \choice Blue
    \choice Yellow
    \correctchoice White
    \choice Black

  \question Which of these things doesn't fit in?
      \choice John
    \choice Paul
    \choice George
    \choice Ringo
    \correctchoice Socrates

    \question Who's buried in Grant's tomb?
    \choice Washington
    \choice Mickey Mouse
    \correctchoice Grant
\end{questions}

\showanswers
\newpage



\begin{questions}
  \question $1+1= \mathord{?}$
    \choice $0$ \choice $1$ \correctchoice $2$ \choice $3$ \choice $4$

  \question $\sin \frac{\pi}{2} = \mathord{?}$
    \choice $0$ \correctchoice $1$ \choice $2$ \choice $\frac{\pi}{2}$

  \question What was the color of the bus driver's eyes?
    \choice Green \choice Yellow \correctchoice Blue \choice Red
\end{questions}

\showanswers

\end{document}

答案2

下面从考试文档类中提取了问题环境和 oneparchoices 环境的基本内容,但我将 oneparchoices 名称更改为普通旧选项,因为它是您在这里唯一要使用的名称。这样就省去了考试类中您不需要的所有额外负担。您可以将其与常规文章类(或您喜欢的任何其他类)一起使用。

为了收集所有正确的选择,我们使用\hbox,但我们使用命令将其放到页面上\unhbox,这样当它到达页面时它就不会在框中,因此不会干扰换行符。

这是一个完整的 LaTeX 文件,它说明了(几乎)所有内容。

\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}

答案3

我用考试文件类进行多项选择测试。它可能不会完全按照您描述的方式运行,但它经过深思熟虑,并且可合理定制。软件包页面上的文档包含许多示例,您可以浏览以查看它是否足够。

特别是,它具有在源代码中指示正确答案的选项,并且可以通过一行命令在学生版本(无答案)和教师版本(指示正确答案)之间切换。

答案4

LaTeX 替代品 Context 也具有一些对测试设计有用的功能。Context 的创建者 (Hans Hagen) 设计了许多大学教材。

相关内容