4

How to replace text on answerline

As per exam class manual; i'm able to add answerline for MCQ using tex mentioned below

\begin{questions}
\question
Who’s buried in Grant’s tomb?
\answerline
\question
What was the color of George Washington’s white horse?
\answerline
\question
Which is heavier: A pound of feathers, or a pound of lead?
\answerline
\end{questions}

which gives output as enter image description here

I'm looking for option to get it updated as

enter image description here

Can you please suggest; how to achieve this?

6

You can redefine \answerline:

\documentclass{exam}

\makeatletter
\renewcommand\answerline[1][{}]{%
  % One optional argument, the default value of which is empty.
  \ifx\@queslevel\ques@ref
    \let\ans@l=\questionlabel
  \else
    \ifx\@queslevel\part@ref
      \let\ans@l=\partlabel
    \else
      \ifx\@queslevel\subpart@ref
        \let\ans@l=\subpartlabel
      \else
        \ifx\@queslevel\subsubpart@ref
          \let\ans@l=\subsubpartlabel
        \else
          % Oops; no question level defined.
          % We must be outide of the questions environment.
          % Just leave out the label, I guess:
          \def\ans@l{}%
        \fi
      \fi
    \fi
  \fi
  \par \nobreak \vskip \answerskip
  \hfill Answer)~%
  \ifprintanswers
    %\ans@l~
\hbox to 0pt{\hbox to \answerlinelength{\hrulefill}\hss}%
    \raise \answerclearance\hbox to \answerlinelength{%
      \CorrectChoice@Emphasis \hfil #1\hss}%
  \else
    %\ans@l~
\hbox to \answerlinelength{\hrulefill}%
  \fi
  \par
}% answerline
\makeatother
\begin{document}

\begin{questions}
\question
Who’s buried in Grant’s tomb?
\answerline
\question
What was the color of George Washington’s white horse?
\answerline[mmm]
\question
Which is heavier: A pound of feathers, or a pound of lead?
\answerline
\end{questions}

\end{document}

enter image description here

5

At the expense of loading an additional package (xpatch), you can quickly patch the existing \answerline macro.

\documentclass{exam}
\def\NewAnswerLabel{Answer)}
\usepackage{xpatch}% http://ctan.org/pkg/etoolbox
\xpatchcmd{\answerline}% <cmd>
  {\questionlabel}% <search>
  {\NewAnswerLabel}% <replace>
  {}{}% <success><failure>
\begin{document}
\begin{questions}
\question
Who’s buried in Grant’s tomb?
\answerline
\question
What was the color of George Washington’s white horse?
\answerline
\question
Which is heavier: A pound of feathers, or a pound of lead?
\answerline
\end{questions}
\end{document}

I learned about \answerline and patching it from the following questions/answers:

Modifying \answerline in the exam class

\answerline to the right of a question

\answerline to the right of a question with dot line between answer line and question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.