31

I am making a sheet where people can fill in answers of various types. For this I would like to make some boxes of certain width and height. How can this best be done? I use \fbox when I want to box a box around some text, but now I need to make a box with given dimensions.

I did noticed the question What are the different kinds of boxes in (La)TeX? but don't quite see the answer there.

1

4 Answers 4

41

You can use \framebox(200,300){} where the size is given in multiples of \unitlength, defaulting to 1pt.

4
  • Nice, but unfortunately, seems you can't use this with predefined values, this \framebox(\textwidth,300){} generates an error message (but does generate a box!).
    – kebs
    Nov 18, 2020 at 18:47
  • 1
    But first comment by @egreg in this question gives a nice solution: \framebox[\textwidth]{\rule{0pt}{80pt}}
    – kebs
    Nov 18, 2020 at 18:52
  • @kebs you can now (since the 2020-10-01 release) Nov 18, 2020 at 19:02
  • Great, thanks! (I use TeXlive 2020, will probably get that update soon).
    – kebs
    Nov 18, 2020 at 20:22
7

Surprised no one has mentioned this. Latex has feature specifically for questions and answers:

% allow for answer boxes:
\documentclass[12pt]{exam}
\printanswers

\usepackage{amsmath}

\begin{document}
\begin{enumerate}

    % questions can be list items
    \item (Problem 7 \S 2.1)\\
    Evaluate the following expression using Euclid's algorithm (2.1.3). (\textbf{Write each step down for credit})

    \[\gcd(98,\ 35)\]

    % make an answer box
    \begin{solutionorbox}[2in] \\
    $98\mod 35 = 28$ \\
    $35\mod 28 = 7$ \\
    $28\mod 7 = 0$ \\
    $\gcd(98,\ 35) = 7$
    \end{solutionorbox}

    \end{enumerate}
\end{document} 

To add, if you need space for students to work on this printed out, you can use vspace.

% answer box with space
\begin{solutionorbox}
\vspace{10cm}
\end{solutionorbox}
6

To make empty boxes that align nicely with the text, you can combine \fbox with \phantom in this way:

\fbox{\phantom{This is my answer}}

You set the width and height by the width and height of the text in \phantom. The resulting box will align perfectly with a line of text, contrarily to the box created with \framebox .

0

For the record, and probably not the "best" solution, here is another technique. I used it before discovering the above accepted answer. It can be useful if your document already uses the "listings" package. If not, you probably should rely on above solution.

It produces an empty framed box whose height is exactly the number of empty lines you put inside.

MWE:

\documentclass{article}    
\usepackage{listings} 
\lstset{
    frame=single,
    showlines=true
}

\begin{document}
text before
\begin{lstlisting}




\end{lstlisting}
text after
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .