将 \answerline 变成考试课中的一个框

将 \answerline 变成考试课中的一个框

我非常喜欢考试类,经常用它来写测试。我希望能够将其变成\answerline一个框,同时保留切换解决方案的能力answers。理想情况下,我还能够全局设置宽度和高度,同时可以选择针对给定问题覆盖它。有人有什么建议吗?

\documentclass{exam}

\begin{document}
\begin{questions}
    \question This is a question. \answerline
\end{questions}
\end{document}

答案1

我基本上复制了 的定义。由于四面都有间隙,所以\answerline盒子更大,但我认为将答案放入给定的空间更重要。\fboxsep

\documentclass{exam}

\makeatletter
\newcommand\answerbox[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 
  \ifprintanswers
    \ans@l~\fbox{\hbox to \answerlinelength{%
      % 2016/05/10: Added \color@begingroup and \color@endgroup:
      \color@begingroup
      \CorrectChoice@Emphasis \hfil #1\hss
      \color@endgroup}}%
  \else
    \ans@l~\fbox{\strut\hspace{\answerlinelength}}%
  \fi
  \par
}% answerbox
\makeatother

\begin{document}
\begin{questions}
    \question This is a question. \answerline[with answer]
    \question How high is up? \answerbox[with answer]
\end{questions}
\end{document}

相关内容