[Tex/LaTex] Empty box with textwidth and specified height

boxes

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!

Best Answer

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).