![在考试中创建带有分值的答案行](https://linux22.com/image/412383/%E5%9C%A8%E8%80%83%E8%AF%95%E4%B8%AD%E5%88%9B%E5%BB%BA%E5%B8%A6%E6%9C%89%E5%88%86%E5%80%BC%E7%9A%84%E7%AD%94%E6%A1%88%E8%A1%8C.png)
我正在创建考试并尝试格式化答案行,但遇到了很多麻烦。我的理想格式是:
问题
垂直空间(用于工作)
然后是右对齐的答案空间,看起来像 ____________ [3]
我尝试了一些随机方法,现在正准备创建一个新的“问题结束”命令 \qend。这是我目前所做的:
\documentclass{exam}
\usepackage[utf8]{inputenc}
\pointsdroppedatright
\bracketedpoints
\newcommand{\qend}{\newline \hfill \rule{2cm}{0.4pt} \droppoints}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{center}\textbf{Basic Quiz}
\end{center}\vspace{0.2cm}
Name: \hrulefill \hspace{0.1cm} Date: \hrulefill
\vspace{0.4cm}
Answer each question completely and to the best of your ability. Show all of your workings in the space provided.
\vspace{0.4cm}
\begin{questions}
\question[3] If blah, then blah. \\ Explain the effect of this logical statement in basic conversation. \vspace{2cm} \qend
\end{questions}
\end{document}
不幸的是,由于 \rule 仍然是左对齐,因此该命令不起作用。
我尝试了 \par,但是它将点放在了新行上,这不是我想要的。
任何帮助都将不胜感激!
答案1
如果你看一下考试类,你应该看到已经有一个宏来实现你想要的:\answerline
。
使用此宏,您还可以通过可选参数添加答案,并更改答案允许的空间或答案行的长度。
我们只需改变行为以在行尾添加点并删除行前出现的问题的标签。为此,我添加\droppoints
和\answerline
删除了标签的定义。
\makeatletter
\renewcommand\answerline[1][{}]{%
\par \nobreak \vskip \answerskip
\hfill
\ifprintanswers
\hbox to 0pt{\hbox to \answerlinelength{\hrulefill}\droppoints\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
\hbox to \answerlinelength{\hrulefill}\droppoints%
\fi
\par
}
\makeatother
但是,由于 droppoints 命令,这在线和点之间留下了空白粘连。所以我们还必须修复这个问题。最后我们得到了:
\documentclass{exam}
\usepackage[utf8]{inputenc}
\pointsdroppedatright
\bracketedpoints
%%%%%%% renewcommand to have \droppoints in the \answerline commands.
\makeatletter
\renewcommand\droppoints{%
\leavevmode\unskip\nobreak%\hfill
\rlap{\hskip\rightmargin % Defined by the list environment
\hskip\@rightmargin % Defined by exam.cls
\hskip-\rightpointsmargin
\llap{\padded@point@block}%
}% rlap
\par
}
\renewcommand\answerline[1][{}]{%
\par \nobreak \vskip \answerskip
\hfill
\ifprintanswers
\hbox to 0pt{\hbox to \answerlinelength{\hrulefill}\droppoints\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
\hbox to \answerlinelength{\hrulefill}\droppoints%
\fi
\par
}
\makeatother
%\printanswers %To print answers
%\setlength\answerskip{2ex} %To set the space for answers.
%\setlength\answerlinelength{1in} %To set the length of the line.
\begin{document}
\begin{center}\textbf{Basic Quiz}
\end{center}\vspace{0.2cm}
Name: \hrulefill \hspace{0.1cm} Date: \hrulefill
\vspace{0.4cm}
Answer each question completely and to the best of your ability. Show all of your workings in the space provided.
\vspace{0.4cm}
\begin{questions}
\question[3] If blah, then blah. \\ Explain the effect of this logical statement in basic conversation.
\answerline[this is the answer]
\end{questions}
\end{document}
最终输出:
答案2
解决了,只需稍作调整。我知道还有其他解决方案,但我能够使用以下命令实现所需的效果:
\newcommand{\qend}{\newline \hspace*{\fill} \makebox{\underline{\hspace{2cm}} \hspace{-1.2cm} \droppoints}}
谢谢您的帮助,如果您认为有更简单的解决方案,请随时做出贡献。