Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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

share|improve this answer
    
Thanks a lot Sir. This is very much useful. –  Pawan Mude Feb 10 at 14:14

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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