You can remove the separation by patching \answerline
with 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}
This will remove the skip for all \answerline
s. Alternatively, on a case-by-case basis, you can set \answerskip
carefully:
\question Write hello%
\setlength{\answerskip}{\dimexpr-\baselineskip-\parskip}
\answerline[hello]
Further modifications are also possible. The following MWE incorporates the above changes, but also provides a starred variant of \answerline
that removes the number before the answer and allows for things to follow \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
provides the means to store macros with optional arguments created using \newcommand
.
\answerline
is placed a line below\question
but you want both of them to be in the same line? (If so, please state it, if not, please tell us your problem to be solved.) (A\vspace{-2\baselineskip}
before\answerline
could help, but there is probably some better solution, if that is indeed the issue here.)\answerline*
) to remove the number typesetting.