6

I'm writing a math test in the exam class, and I want to make framed boxes for the students to write their answer in. I've tried this solution, but the box exceeds the right page margin by 6.79999pts. What's going wrong here?

MWE:

\documentclass[12pt, a4paper]{exam}
\RequirePackage{amssymb, amsfonts, amsmath, latexsym, verbatim, xspace, setspace}
\usepackage[margin=1in,showframe]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage{calc}

\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{calc}

\newlength{\whatsleft}
\newcommand{\measureremainder}[1]{%
\begin{tikzpicture}[overlay,remember picture]
    % Measure distance to right text border
    \path let \p0 = (0,0), \p1 = (current page text area.east) in
        [/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
\end{tikzpicture}%
}

\onehalfspacing

\begin{document}
\begin{questions}
\addpoints
\question[8] \emph{Regn ut:}
\begin{parts}
    \part[2] $6-(-4) = $ \measureremainder{\whatsleft}\fbox{\begin{minipage}{\whatsleft}\vspace{2em}\hfill\end{minipage}}
\end{parts}

\end{questions}
\end{document}

Resulting in

enter image description here

Holene
  • 6,920

1 Answers1

7

You need to take account of the box padding

\begin{minipage}{\whatsleft-2\fboxsep-2\fboxrule}

but you don't need tikz for this really, you could just use classic TeX leaders.

\documentclass[12pt, a4paper]{exam}
\RequirePackage{amssymb, amsfonts, amsmath, latexsym, verbatim, xspace, setspace}
\usepackage[margin=1in,showframe]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage{calc}

\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{calc}

\newlength{\whatsleft}
\newcommand{\measureremainder}[1]{%
\begin{tikzpicture}[overlay,remember picture]
    % Measure distance to right text border
    \path let \p0 = (0,0), \p1 = (current page text area.east) in
        [/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
\end{tikzpicture}%
}

\onehalfspacing

\begin{document}
\begin{questions}
\addpoints
\question[8] \emph{Regn ut:}
\begin{parts}
    \part[2] $6-(-4) = $ \measureremainder{\whatsleft}\fbox{\begin{minipage}{\whatsleft-2\fboxsep-2\fboxrule}\vspace{2em}\hfill\end{minipage}}
\end{parts}

\question[8] \emph{Regn ut:}
\begin{parts}
    \part[2] $6-(-4) = $ \vrule\leaders\vbox{\offinterlineskip\hrule width.1pt\vskip\normalbaselineskip\hrule\kern-\dp\strutbox\hrule width0pt depth\dp\strutbox}\hfill\vrule\mbox{}\\dd
\end{parts}

\end{questions}
\end{document}
David Carlisle
  • 757,742