0

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

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

1 Answer 1

0

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

\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
      \def\ans@ll{\thequestion\thepartno.}   % <---
      \let\ans@l\ans@ll                      % <---
    \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 
  \ifprintanswers
    \ans@l~\hbox to 0pt{\hbox to \answerlinelength{\hrulefill}\hss}%
    \raise \answerclearance\hbox to \answerlinelength{%
      % 2016/05/10: Added \color@begingroup and \color@endgroup:
      \color@begingroup
      \CorrectChoice@Emphasis \hfil #1\hss
      \color@endgroup}%
  \else
    \ans@l~\hbox to \answerlinelength{\hrulefill}%
  \fi
  \par
}% answerline

\makeatother

% Longer answer lines
%\setlength\answerlinelength{1.5in}

\begin{document}
\begin{questions}
\question
Subquestions

\begin{parts}
\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
\end{parts}
\end{questions}
\end{document}
1
  • This is exactly what I was trying to do! THANK YOU.
    – SmellyGoat
    Commented 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 .