答案环境应该提供我想要的不同字体和不同大小。我该怎么办?

答案环境应该提供我想要的不同字体和不同大小。我该怎么办?

我正在用这些代码编写我的试卷。

\documentclass[10.5pt,a4paper,addpoints]{exam}

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


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

\newcommand{\showallanswers}{{Answe Key:\\ \par\unvbox\allanswers}}
% End Phil's answer


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

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

我希望我的答案必须采用不同的字体和不同的字体大小。

我怎样才能做到这一点?

答案1

我不会走这\vbox条路。我更喜欢在最后添加标记并交付,这样您就可以在现场适当地定义输出。

\documentclass[a4paper,addpoints]{exam}

\usepackage{environ,etoolbox}

\newcommand\allanswers{} % initialize
\makeatletter
\NewEnviron{answer}
 {%
  % we want to expand \thequestion
  \protected@edef\BODY{\BODY}%
  % just expand once \BODY; \noexpand is in case \par is not the primitive
  \xappto\allanswers{\expandonce{\BODY}\noexpand\par}%
  \bigbreak
 }
\makeatother
\newcommand{\showallanswers}{%
  Answer Key:\par\nopagebreak\medskip
  {\setlength\parindent{0pt}\footnotesize\allanswers}%
}
% End Phil's answer


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

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

在此处输入图片描述

使用您的代码(和\vbox),只需在之后添加\footnotesize(或您想要的大小)\vbox\bgroup

相关内容