In the exam class, is there a way to modify \answerline to include the question number and part? I design tests for 50+ teachers, and this is one feature they requested. After thorough research and trying different solutions, I haven't found a way to do this yet.

What I want:

enter image description here

What I'm getting: enter image description here

BONUS POINTS (but I don't care about this one as much but thought I could ask): Some teachers would like "x=" along with the answer line, but this doesn't apply to every problem. Is there a way to do this with \answerline, or should I just tell teachers "TSB (too stinking bad)." An example is below:

enter image description here

  • Welcome. // Please add the relevant code, starting with \documentclass.
    – MS-SPO
    Jul 20, 2022 at 16:42

1 Answer 1


You have to change the \answerline definition. It only works for parts.


  % One optional argument, the default value of which is empty.
      \def\ans@ll{\thequestion\thepartno.}   % <---
      \let\ans@l\ans@ll                      % <---
          % Oops; no question level defined.
          % We must be outide of the questions environment.
          % Just leave out the label, I guess:
  \par \nobreak \vskip \answerskip
    \ans@l~\hbox to 0pt{\hbox to \answerlinelength{\hrulefill}\hss}%
    \raise \answerclearance\hbox to \answerlinelength{%
      % 2016/05/10: Added \color@begingroup and \color@endgroup:
      \CorrectChoice@Emphasis \hfil #1\hss
    \ans@l~\hbox to \answerlinelength{\hrulefill}%
}% answerline


% Longer answer lines


\part[5] $f(x) = x^2+2x+1$. Find $f(2)$. \answerline
\part[5] $g(x) = x^3-2x^2+x+1$. Find $g(3)$. \answerline
  • This is exactly what I was trying to do! THANK YOU.
    – SmellyGoat
    Jul 21, 2022 at 18:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .