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

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}
  • Could you please give an example of how to solve this with "classic TeX leaders"? =) – Holene Oct 3 '13 at 9:04
  • 1
    @Holene example added (sorry I had a meeting:-) – David Carlisle Oct 3 '13 at 10:04
  • 1
    @Holene, David Carlisle IS a "classic TeX leader!" – Steven B. Segletes Oct 3 '13 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.