Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 7 down vote accepted

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}
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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