问题右侧的 \answerline

问题右侧的 \answerline

使用exam类。我希望答案行与问题在同一行,实际上是在句子中间使用。

我有这个:

\documentclass[a4paper]{exam}
\begin{document}
\begin{questions}
\question Write hello  \answerline[hello] to your mother
\end{questions}
\end{document}

答案1

\answerline您可以通过以下方式消除分离:xpatch

在此处输入图片描述

\documentclass[a4paper]{exam}
\usepackage{xpatch}% http://ctan.org/pkg/etoolbox
\xpatchcmd{\answerline}% <cmd>
  {\par\nobreak\vskip\answerskip}% <search>
  {}% <replace>
  {}{}% <success><failure>
\begin{document}
\begin{questions}
\question Write hello  \answerline[hello]
\end{questions}
\end{document}

这将删除跳过全部 \answerlines. 或者,您可以根据具体情况\answerskip谨慎设置:

\question Write hello%
\setlength{\answerskip}{\dimexpr-\baselineskip-\parskip}
\answerline[hello]

还可以进行进一步的修改。以下 MWE 结合了上述更改,但也提供了一个带星号的变体,\answerline删除了答案前的数字,并允许以下内容\answerline

在此处输入图片描述

\documentclass[a4paper]{exam}
\usepackage{letltxmacro}% http://ctan.org/pkg/letltxmacro
\usepackage{xpatch}% http://ctan.org/pkg/etoolbox
\xpatchcmd{\answerline}% <cmd>
  {\par\nobreak\vskip\answerskip}% <search>
  {}% <replace>
  {}{}% <success><failure>
\xpatchcmd{\answerline}{\fi \par}{\fi}{}{}% Remove line break after \answerline
\makeatletter
\LetLtxMacro{\oldanswerline}{\answerline}
\RenewDocumentCommand{\answerline}{s o}{%
  \begingroup
  \IfBooleanTF{#1}
    {\def\@queslevel{\relax}}% \answerline*
    {}% \answerline
  \IfNoValueTF{#2}
    {\oldanswerline[{}]}% \answerline
    {\oldanswerline[#2]}% \answerline[..]
  \endgroup
}
\makeatother
\begin{document}
\begin{questions}
\question Write hello  \answerline[hello] to your mother
\question Write hello  \answerline*[hello] to your mother
\question Write hello  \answerline[hello] to your mother
\end{questions}
\end{document}

letltxmacro提供了使用 创建的带有可选参数的宏的存储方法\newcommand

答案2

您可以使用 \fillin 环境来代替。请参阅5.6 填空题使用考试文档类

\documentclass[a4paper]{exam}
\begin{document}
\begin{questions}
\question Write hello \fillin[hello] to your mother
\end{questions}
\end{document}

相关内容