Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Does anyone know how to stretch a (framed) box down to the end of the page? In effect something like

\documentclass{scrartcl}

\begin{document}
sometext

\framebox[\textwidth]{somemoretext\vspace*{\fill}}
\end{document}

Only that this doesn't work, of course, because \fill doesn't work inside a box...

I've also tried the framed package, that doesn't solve the problem either.

(In case anyone is wondering why I'm trying to do this, think of a handout with a box for handwritten comments at the end...)

share|improve this question

4 Answers 4

up vote 4 down vote accepted

run it with xelatex

\documentclass{article}
\usepackage{pst-node}
\begin{document}
sometext

\rnode[lt]{A}{somemoretext}

\vfill
~\hfill\rnode[rb]{B}{~}
\psframe(A)(B)

\clearpage
foo
\end{document}

enter image description here

share|improve this answer

Update 2011/09/16

Herbert is right with his approach to use two nodes and v/hfill. Here my TikZ solution based on this idea:

\documentclass{scrartcl}
\usepackage{capt-of}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}


\begin{document}
\lipsum[1]% dummy text

\par\noindent
\tikz[overlay,remember picture]\coordinate (image-start);
\par
\vfill
\null\hfill
\tikz [overlay,remember picture] \draw (0,0) rectangle ([yshift=\ht\strutbox-\fboxsep]image-start);
\newpage
\end{document}

You can use TikZ for this. There is the special node current page which gives you the corners of the current page as points of the compass. You can get the lower right corner of the textarea by subtracting the margins. This needs the remember picture and overlay option on the picture and also needs two compiler runs to produce the correct result.

Unfortunately TikZ doesn't provide a special node for the text area itself, but I found some code posted by Sven Köhler which defines such a node.

\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{lipsum}

\newcommand{\currentsidemargin}{%
  \ifodd\value{page}%
    \oddsidemargin%
  \else%
    \evensidemargin%
  \fi%
}

\begin{document}
\lipsum[1]% dummy text
\par\bigskip \noindent
Notes:\\
\begin{tikzpicture}[overlay,remember picture]
    % Helper nodes
    \path (current page.north west) ++(\hoffset, -\voffset)
        node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth, minimum height=\paperheight]
        (pagearea) {};

    \path (pagearea.north west) ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep)
        node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
        (textarea) {};

    % Framebox
    \draw (0,0) rectangle (textarea.south east);

\end{tikzpicture}
\newpage
\end{document}

Result

share|improve this answer

Stumbling across How to define a figure size so that it consumes the rest of a page?, I learned a much simpler answer to this problem, avoiding "big machinery" like TikZ or pstricks: the space remaining on the page can be calculated with the primitives \pagegoal and \pagetotal. Thus

\def\restofpage{\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}

is the height of the remainder of the page. Therefore,

\documentclass[paper=a8]{scrartcl}

\def\restofpage{\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}

\begin{document}
sometext

\medskip

\framebox[\textwidth]{\parbox{\textwidth}{somemoretext\par\vspace{\restofpage}}}
\end{document}

produces the desired output:

crop of compiled document

Note that \framebox puts its argument in an \hbox (cf. e.g. this answer) so the \parbox is in fact necessary.

share|improve this answer

There's also a tcolorbox solution (using tikz in the background):

\documentclass{scrartcl}
\usepackage{lipsum}
\usepackage[breakable]{tcolorbox}

\newtcolorbox{stretchbox}[1][]{
  height fill,
  sharp corners,
  colback=yellow!10!white,
  colframe=yellow!50!black,
  #1}

\begin{document}
\lipsum[1]

\begin{stretchbox}
\lipsum[2]
\end{stretchbox}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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