2

I'm making some boxes for providing answers. The box macro takes the height of the box as an argument. I need to measure the remaining space from the line the box starts at, to the bottom of the page.

Consider the following MWE. The first box has the length I want, I need to provide the remaining length to the end of the page as an argument to the second box. How may I achieve this?

(Bonus question: why do I get Underfull \hbox (badness 10000) in paragraph error in this MWE?)

\documentclass[]{article}

\newcommand\mybox[1]{\vrule\leaders\vbox{\offinterlineskip\hrule width.1pt\vskip#1\hrule\kern-\dp\strutbox\hrule width0pt depth\dp\strutbox}\hfill\vrule\mbox{\vspace*{2em}}\\}

\begin{document}
    Please provide the answer in the box below \par\mybox{1in}

    Please provide the answer in the box below \par\mybox{4in}
\end{document}
  • 2
    you have \\ at end of paragraph. \\ anywhere is usually wrong. at end of paragraph it is always wrong and will always give you underful boxes. – David Carlisle Dec 8 '14 at 9:28
  • @DavidCarlisle Actually, you have \\ at the end of the paragraph. But I see your point ;-) – Holene Dec 8 '14 at 10:01
4

No box requirements can go without a solution using tcolorbox!

tcolorbox provides height fill option to fill the remaining space in the page.

\documentclass[]{article}
\usepackage[most]{tcolorbox}
\newtcbox{example}[1][]{%
  enhanced jigsaw,
  colback=white, 
  colframe=black,
  boxrule=1pt,
  sharpish corners,
  arc=0mm,
  boxsep=0mm,
  left=\dimexpr\textwidth-2pt\relax,   %% 2pt= 2* boxrule width (1pt)
  right=0mm,
  %width=\textwidth,
  height fill,   %% <---- ths fills the remaining space
  #1,
}

\newcommand\mybox[1]{\vrule\leaders\vbox{\offinterlineskip\hrule width.1pt\vskip#1\hrule\kern-\dp\strutbox\hrule width0pt depth\dp\strutbox}\hfill\vrule\mbox{\vspace*{2em}}\\}

%\usepackage{showframe}
\begin{document}
    Please provide the answer in the box below \par\mybox{1in}

    Please provide the answer in the box below \par\example{\null}
\end{document}

enter image description here

Advantage here is your box can be made very fancy.

  • Ooooh, fancybox! I'd tap that! – Holene Dec 8 '14 at 10:03
  • I get I do not know the key '\tbc\sharpish corners' and ... \tbc\height fill error when I try to compile your example... – Holene Dec 9 '14 at 6:41
  • 1
    @Holene Please update tcolorbox. – user11232 Dec 9 '14 at 13:01
  • Done! How can I get tcolorbox to fill the width of the line? – Holene Dec 11 '14 at 13:20
  • @Holene It is already filling the width, isn't it? – user11232 Dec 11 '14 at 13:26

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.