在考试中创建带有分值的答案行

在考试中创建带有分值的答案行

我正在创建考试并尝试格式化答案行,但遇到了很多麻烦。我的理想格式是:

问题

垂直空间(用于工作)

然后是右对齐的答案空间,看起来像 ____________ [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}}

谢谢您的帮助,如果您认为有更简单的解决方案,请随时做出贡献。

相关内容