TransWikia.com

Creating an answer line with point value in an exam

TeX - LaTeX Asked by Weezbee on March 28, 2021

I’m creating an exam and trying to format the answer line, and having a world of trouble with it. My ideal format is to have:

The question

Vertical space (for workings)

Then a right-aligned answer space that would look like ____________ [3]

I’ve tried a few random things, and am at the point of making a new “question end” command qend. This is what I have so far:

    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}

Unfortunately, this command does not work since the rule is still left-aligned.

I tried par, but it puts the points on a new line, which is not what I’m looking for.

Any help is appreciated!

2 Answers

If you have a look in the document of the exam class, you should see there is already a macro to achieve what you want : answerline.

With this macro, you can also add the answer by optionnal argument and change the space allowed for answers or the length of the answer lines.

We only have to change the behaviour to add the points at the end of the lines and to remove the label of the question presents just before the line. To do that, I add droppoints in answerline and remove the definitions of label.

makeatletter
renewcommandanswerline[1][{}]{%
    par nobreak vskip answerskip
    hfill 
    ifprintanswers
    hbox to 0pt{hbox to answerlinelength{hrulefill}droppointshss}%
    raise answerclearancehbox to answerlinelength{%
        % 2016/05/10: Added color@begingroup and color@endgroup:
        color@begingroup
        CorrectChoice@Emphasis hfil #1hss
        color@endgroup}%
    else
    hbox to answerlinelength{hrulefill}droppoints%
    fi
    par
}
makeatother

enter image description here

But this leave a white space glue between the line and the points due to the droppoints command. So we have to fix this also. And we have finally :

documentclass{exam}
usepackage[utf8]{inputenc}
pointsdroppedatright
bracketedpoints


%%%%%%%  renewcommand to have droppoints in the answerline commands.
makeatletter
renewcommanddroppoints{%
    leavevmodeunskipnobreak%hfill
    rlap{hskiprightmargin  % Defined by the list environment
        hskip@rightmargin % Defined by exam.cls
        hskip-rightpointsmargin
        llap{padded@point@block}%
    }% rlap
    par
}
renewcommandanswerline[1][{}]{%
    par nobreak vskip answerskip
    hfill 
    ifprintanswers
    hbox to 0pt{hbox to answerlinelength{hrulefill}droppointshss}%
    raise answerclearancehbox to answerlinelength{%
        % 2016/05/10: Added color@begingroup and color@endgroup:
        color@begingroup
        CorrectChoice@Emphasis hfil #1hss
        color@endgroup}%
    else
    hbox to answerlinelength{hrulefill}droppoints%
    fi
    par
}
makeatother



%printanswers                      %To print answers
%setlengthanswerskip{2ex}         %To set the space for answers.
%setlengthanswerlinelength{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}

Final output :

enter image description here

Answered by Piroooh on March 28, 2021

Resolved, with a little tweaking. I recognize there are other solutions to this, but I was able to achieve the desired effect with this command:

    newcommand{qend}{newline hspace*{fill} makebox{underline{hspace{2cm}} hspace{-1.2cm} droppoints}}

Thank you for your help, and feel free to contribute if you think there is an easier solution.

Answered by Weezbee on March 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP