2

This question already has an answer here:

I am trying to make a document containing a box with text that i want to appear a certain exact size when i print it. (Specifically I want to make a nametag that fits exactly inside a slot on my mailbox.) Here's a MWE:

\documentclass[a4paper]{article}

\begin{document}
\fbox{
\begin{minipage}[c][3cm][c]{7.5cm}
    words
\end{minipage}
}
\end{document}

The problem is that when i measure the lengths in the PDF (in Preview on macOS and printed on paper), the box is not 7.5 cm by 3 cm but rather (approximately) 7.9 cm by 3.2 cm. The paper size looks fine in Preview (approx. 21 cm by 29.7 cm).

Is this an issue with the method I used to create the box, e.g. the \fbox doesn't fit exactly around the minipage? Or is it something else? Is there a better way to do this? I'm lost.

marked as duplicate by Schweinebacke, Zarko, ebosi, Mico, clemens Feb 7 '17 at 14:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    You have at least a space before and after your minipage; you should add % at the end of some lines. And note that \fbox adds \fboxsep space between the object and the frame. – Martin Schröder Feb 6 '17 at 11:56
  • 2
    to see why the spaces matter compare \fbox{ x } with \fbox{x} – David Carlisle Feb 6 '17 at 12:13
  • A few %s and \setlength{\fboxsep}{0pt}did the trick. Cheers! – lydhvin Feb 6 '17 at 12:16
1

Besides what others have already mentioned in the comments, here is a comparison with a \rule{7.5cm}{3cm} after subtracting 2*\fboxrule width (2*0.4pt) to get the exact overall width of 7.5cm by 3cm.

\documentclass[a4paper]{article}
\setlength{\parindent}{0pt}
\begin{document}

\setlength{\fboxsep}{0pt}    
\fbox{%
\begin{minipage}[c][\dimexpr3cm-2\fboxrule][c]{\dimexpr7.5cm-2\fboxrule}
    words
\end{minipage}%
}

\rule{7.5cm}{3cm}    
\end{document}

enter image description here

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