TransWikia.com

How to make an empty box

TeX - LaTeX Asked on February 21, 2021

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.

4 Answers

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

Correct answer by David Carlisle on February 21, 2021

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] 
    $98mod 35 = 28$ 
    $35mod 28 = 7$ 
    $28mod 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}

Answered by Samy Bencherif on February 21, 2021

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 .

Answered by Gargilius on February 21, 2021

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}

Answered by kebs on February 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP