# Adjusting box height to the document bottom

I made a command that prints a gray rectangle in my document. I can use this command typing:

\notes{100}, where 100 is the vertical size of the box.

\newcommand{\notes}[1]{
\begin{minipage}{0.974\linewidth}
\centering
\begin{tikzpicture}
\node [ draw,
gray!20,
rectangle,
fill=gray!20,
rounded corners,
text width=\linewidth,
minimum height=#1 mm
] (init) {};
\end{tikzpicture}
\end{minipage}
\par
}


I'm looking for a solution that fills the page to the bottom, getting the size of the \vfill.

EDIT: obviously, I need a solution that doesn't need to use some value as parameter.

-
Do you want to fill the remainder of the page after the command with the gray rectangle or print the rectangle and fill all space that is left (with whitespace)? –  Mythio Mar 5 '13 at 10:39
Hi user13596. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) or select your code and hit Ctrl+K. –  Claudio Fiandrino Mar 5 '13 at 10:40
I want to make the gray rectangle expands until the end of space. I want no blank spaces after the command. –  user13596 Mar 5 '13 at 10:48

Here is a solution (using the tikzpagenodes package and the overlay and remember picture options). Note: Several compilation are needed!

\documentclass{article}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage{lipsum}

\newcommand\vfillgrayrectangle{%
\par\noindent%
\begin{tikzpicture}[remember picture,overlay]
\fill[gray!20,rounded corners]
(0,0) rectangle (current page text area.south east);
\end{tikzpicture}%
\newpage
}

\begin{document}
\lipsum[1-2]
\vfillgrayrectangle
\lipsum[3]
\vfillgrayrectangle
\lipsum[5-8]
\vfillgrayrectangle
\lipsum[2]
\vfillgrayrectangle
\lipsum[4]
\vfillgrayrectangle
\end{document}

-
I was about to answer exactly the same, but without [yshift=1mm]. Why is this needed? –  JLDiaz Mar 5 '13 at 11:04
@JLDiaz This is an oversight... –  Paul Gaborit Mar 5 '13 at 12:30
I’d add a \par to the beginning of the definition, so that \vfillgrayrectangle can be used directly following some text. (\lipsum inserts a \par automatically. Try it with \lipsum* instead.) –  Qrrbrbirlbel Mar 5 '13 at 15:19
@Qrrbrbirlbel It's a good advice. Thanks. I edited my answer. –  Paul Gaborit Mar 5 '13 at 15:40