3

Is there a way to draw a simple box with width \textwidth and height so that it fills from wherever it is placed to the bottom margin of the page?

4
  • Which type of box do you want to create? Have you had a look at \vfill?
    – TeXnician
    Commented May 2, 2017 at 5:53
  • @TeXnician he means a visible frame, like \fbox Commented May 2, 2017 at 6:34
  • It can be done, but it isn't simple. It involves measuring the distance to the bottom of the text area from the top of the box (using tikzpagenodes). Commented May 2, 2017 at 15:46
  • @TeXnician yep, I mean a visible frame, thanks for the clarification
    – Ben
    Commented May 3, 2017 at 7:04

2 Answers 2

3

Maybe I still need to fine-tune some parameters, but here is an idea with vertical \leaders that seems to work:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{lipsum}

\makeatletter

\newcommand*\@helper@hboxto@hsize[2]{%
    \hb@xt@ \hsize {%
        \vrule \@width .4\p@ \@height #1\ht\strutbox \@depth #2\dp\strutbox
        \hfil
        \vrule \@width .4\p@ % automatic height and depth
    }
}
\newcommand*\@helper@hrule{%
    \kern -.2\p@
    \hrule \@height .2\p@ \@depth .2\p@
    \kern -.2\p@
}
\newcommand*\boxcolumnfill{%
    \par
    \vskip \dimexpr \dp\strutbox-\prevdepth
    \@helper@hrule
    \@helper@hboxto@hsize{.25}{.25}%
    \nobreak
    \xleaders \vbox {
                \kern -.25\ht\strutbox
                \@helper@hboxto@hsize{.5}{.5}%
                \kern -.25\dp\strutbox
            }\vfill
    \kern -.25\dp\strutbox
    \nointerlineskip
    \@helper@hboxto@hsize{.25}{0}%
    \@helper@hrule
    \break
}

\makeatother



\begin{document}

With some text before.
\lipsum*[1]
Is the positioning affected by the presence of descenders?
% Uncomment this line to find it out: Qfgjpqy.
\boxcolumnfill

\lipsum[2]

Whole pages of boxes follow.

\newpage
\boxcolumnfill
\boxcolumnfill

Some more text.

\end{document}

Addition

Here is another version of the code, that endows the \boxcolumnfill command with an optional argument, in which you can specify an amount of additional whitespace to be inserted above the top horizontal rule:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{lipsum}

\makeatletter

\newcommand*\@helper@hboxto@hsize[2]{%
    \hb@xt@ \hsize {%
        \vrule \@width .4\p@ \@height #1\ht\strutbox \@depth #2\dp\strutbox
        \hfil
        \vrule \@width .4\p@ % automatic height and depth
    }
}
\newcommand*\@helper@hrule{%
    \kern -.2\p@
    \hrule \@height .2\p@ \@depth .2\p@
    \kern -.2\p@
}

% The user-level command; in the optional argument you can specify additional 
% whitespace to be inserted above the horizontal rule.
\newcommand*\boxcolumnfill[1][\z@]{%
    \par
    % Not yet sure: provide a legal breakpoint here, just in case the user 
    % passes an argument that is too tall?
    % \penalty \@highpenalty
    \kern \dimexpr \dp\strutbox-\prevdepth
                % The additional "\dimexpr" around "#1" is actually redundant 
                % here, but you know, Murphy's law...
                +\dimexpr #1\relax
            \relax
    \@helper@hrule
    \@helper@hboxto@hsize{.25}{.25}%
    \nobreak
    \xleaders \vbox {
                \kern -.25\ht\strutbox
                \@helper@hboxto@hsize{.5}{.5}%
                \kern -.25\dp\strutbox
            }\vfill
    \kern -.25\dp\strutbox
    \nointerlineskip
    \@helper@hboxto@hsize{.25}{0}%
    \@helper@hrule
    \break
}

\makeatother

\flushbottom % please note



\begin{document}

With some text before.
\lipsum*[1]
Is the positioning affected by the presence of descenders?
% Uncomment this line to find it out: Qfgjpqy.
\boxcolumnfill

\lipsum[2]

Some additional space above the rule,\\
without descenders.
% Now with descenders: Qfgjpqy.
\boxcolumnfill[\bigskipamount]

If used at the top of a new page, \verb|\boxcolumnfill| prints a box extending
to the full page height, but any additional space is ignored, even if specified.

\newpage
\boxcolumnfill
\boxcolumnfill[10cm]

This text should be on a new page.  Let's try it again:
\boxcolumnfill[10cm]

\lipsum[3-4]

Now, with an argument that is too tall for the available space:
\boxcolumnfill[15cm]

\textbf{Beware:} a negative argument \emph{is} honored!\\
without descenders.
% Now with descenders: Qfgjpqy.
\boxcolumnfill[-2\baselineskip]

Some more text.

\end{document}
4
  • This works pretty well - thanks :) How would I tweak the vertical "padding" between the leading para and the top of the box?
    – Ben
    Commented May 6, 2017 at 8:20
  • @Ben: It’s pretty easy, if you want so, to add an optional argument for specifying an additional amount of whitespace above the top rule; but I’ll postpone this to tomorrow! (:-) Or would you prefer a mandatory argument (you wouldn’t need to worry about the ensuing text beginning with […)?
    – GuM
    Commented May 7, 2017 at 1:17
  • a hardcoded value is fine - I just want a bit more breathing room. No rush, and thanks for your help :)
    – Ben
    Commented May 8, 2017 at 2:53
  • Well, for a hardcoded value of, say, 3.14159mm, just use \kern \dimexpr \dp\strutbox-\prevdepth+3.14159mm \relax.
    – GuM
    Commented May 9, 2017 at 21:06
2

This is easy with tcolorbox package. height fill option creates boxes with height equal to the available space to the end of the page:

\documentclass[a4paper]{article} 
\usepackage[T1]{fontenc}         
\usepackage{lipsum}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}

\begin{document}

With some text before.
\lipsum*[1]
\begin{tcolorbox}[height fill]
\end{tcolorbox}

\lipsum[2]
\begin{tcolorbox}[height fill]
\end{tcolorbox}

\begin{tcolorbox}[height fill]
\end{tcolorbox}

\lipsum[1-2]
\begin{tcolorbox}[height fill]
\end{tcolorbox}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .