Empty box with textwidth and specified height

I want to create empty boxes with a given height and a width of \textwidth. I tried the following:

\framebox(\textwidth{}, 80){} % (a)
\framebox[\textwidth]{}     % (b)


(b) does not work (because I cannot specify the height... ), and (a) works but gives me the following error:

ERROR: Missing number, treated as zero.

I don't really understand why it works with this error... So if anyone could help me figure this out.

I am using exam.cls, so my real code is something like:

\fullwidth{\color{black!30}\framebox(\textwidth{}, 80){}}


But I can reproduce without the \fullwidth... I also checked the value of \textwidth:

\the\textwidth
% 469.755pt


Maybe the problem is the pt at the end but I don't know how to get rid of it...

Of course, if you have other solutions to create empty boxes with specified criteria, I am open to suggestion!

• \framebox[\textwidth]{\rule{0pt}{80pt}}? Nov 25 '16 at 10:04
• @egreg Works perfectlty! Answer?
– Holt
Nov 25 '16 at 10:07
• Do you want to have a frame? Or is this just a result of trying to get empty boxes? Nov 25 '16 at 10:07
• @MaestroGlanz I just want empty boxes to give specific places for student to answer questions.
– Holt
Nov 25 '16 at 10:08

If you need an empty framed box, you can define your own command:

\newcommand{\emptybox}[2][\textwidth]{%
\begingroup
\setlength{\fboxsep}{-\fboxrule}%
\noindent\framebox[#1]{\rule{0pt}{#2}}%
\endgroup
}


so a call of

\emptybox{4cm}


will produce a 4cm high empty box and as wide as the text. With

\emptybox[8cm]{4cm}


you get it 4cm high and 8cm wide. The \setlength instruction ensures no padding is added (otherwise \emptybox{4cm} would produce an overfull line).

• To get a box without a frame, you can use \makebox, which is identical. Providing both could be done via \NewDocumentCommand{s O{\textwidth} m}{...} and a stared version. Nov 25 '16 at 10:38
• @MaestroGlanz An empty space just requires \vspace*{4cm}` Nov 25 '16 at 11:24
• @egreg Not always. Compare $\left\{\vspace*{4cm}\right.$ with $\left\{\emptybox[0cm]{4cm}\right.$. The former does not force the left brace to become longer, but the latter does (and it will do it also if, in the definition of \emptybox, one replaces \framebox by \makebox so that the box doesn't have a frame). Nov 25 '19 at 16:05
• @linguisticturn That code will definitely not produce a 4cm left parenthesis. It's a very different construction that you need. Nov 25 '19 at 16:13
• @egreg Well, the length of the brace will be sort of double the number you put into \emptybox (so ~8cm); on my system, it comes out to 7.87 cm. Is that what you mean? That if you use y cm in \emptybox, the left brace won't be exactly 2y cm, but a bit less? That's true. But putting the \emptybox inside definitely does something to the brace, whereas \vspace* does nothing, as best as I can tell. Nov 25 '19 at 16:29