2

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!

  • 2
    \framebox[\textwidth]{\rule{0pt}{80pt}}? – egreg 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? – MaestroGlanz 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
7

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

  • 2
    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. – MaestroGlanz Nov 25 '16 at 10:38
  • @MaestroGlanz An empty space just requires \vspace*{4cm} – egreg Nov 25 '16 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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