如何调整答案环境以使其看起来像问题环境?

如何调整答案环境以使其看起来像问题环境?

我正在使用这些代码来生成我的试卷......

\documentclass[a4paper,addpoints]{exam}

\newbox\allanswers
\setbox\allanswers=\vbox{}
\def\qn{\question}

\newenvironment{answer}
{%
    \global\setbox\allanswers=\vbox\bgroup\large
    \unvbox\allanswers
}%
{%
    \bigbreak
    \egroup
}

\newcommand{\showallanswers}{{\begin{center}
\vspace{1cm}\large{\textbf{Class Test II(Test for Improvement)\\
Mathematics Foundation\\Answer Key\\
\hrule
%\\Sets and Relations, Matrices, Determinants \& \\Continuity and Differentiation
}}
\end{center}\par\unvbox\allanswers}}
% End Phil's answer

\begin{document}
\begin{questions}
\question First Question First Question First Question First Question First Question First Question First Question First Question First Question 
\begin{answer}
\thequestion. Answer for the first question.  Answer for the first question.  Answer for the first question.  Answer for the first question.  Answer for the first question.  Answer for the first question.  Answer for the first question. 
\end{answer}

\question Second Question
\begin{answer}
\thequestion.  Answer for the second questionAnswer for the second questionAnswer for the second questionAnswer for the second questionAnswer for the second questionAnswer for the second questionAnswer for the second questionAnswer for the second question
\end{answer}
\end{questions}
\showallanswers
\end{document}

通过这些代码我得到了这样的输出。 在此处输入图片描述

我的问题:

看看问题和答案,问题环境像枚举环境一样运行,但答案环境像手动一样工作。意思是说,我不想要答案中编号下面的单词。它应该像问题环境一样。就像这个图一样, 在此处输入图片描述

答案1

如果您希望这些答案的排版像枚举一样,那么最简单的方法是使用enumerate

示例输出

\documentclass[a4paper,addpoints]{exam}

\usepackage{enumitem}

\newbox\allanswers
\setbox\allanswers=\vbox{}

\newenvironment{answer}
{\global\setbox\allanswers=\vbox\bgroup\unvbox\allanswers
\begin{enumerate}[leftmargin=0pt]\item[\thequestion.]\ignorespaces}
{\end{enumerate}\egroup}

\newcommand{\showallanswers}{\par\bigbreak
\begin{center}
  \large\bfseries
  Class Test II (Test for Improvement)\\
  Mathematics Foundation\\
  Answer Key\\[1ex]
  \hrule
\end{center}
\unvbox\allanswers}

\begin{document}

\begin{questions}
\question First Question.
  First Question.
  First Question.
  First Question.
  First Question.
  First Question.
  First Question.
  First Question.
  First Question.
\begin{answer}
  Answer for the first question.
  Answer for the first question.
  Answer for the first question.
  Answer for the first question.
  Answer for the first question.
  Answer for the first question.
  Answer for the first question.
\end{answer}

\question Second Question.
\begin{answer}
  Answer for the second question.
  Answer for the second question.
  Answer for the second question.
  Answer for the second question.
  Answer for the second question.
  Answer for the second question.
  Answer for the second question.
  Answer for the second question
\end{answer}
\end{questions}

\showallanswers
\end{document}

我对你的代码的主要修改是答案的开头添加了

\begin{enumerate}
\item[\thequestion.]

最后加上结尾

\end{enumerate}

这样你就不必自己添加问题编号了。结果发现这给答案留下了很大的左边距,为了解决这个问题,我加载了enumitemleftmargin=0pt在选项中设置了列表。这比使用低级 LaTeX 命令更容易。

相关内容