# Make tikzpicture take remaining space of page

I am trying to place three rectangles on a page using tikz with these equirements

• The two first boxes should have an height of 3.5 (as in my code)
• The remaining box should take the remaining space of the page
• The spacing between the three boxes should be consistent
• I should be able to place some text in the lower left of the lowest box.

The result should look something like this; except that the boxes should be evenly spaced.

My code is shown below and produces the following result

Questions / Problems I have with the code:

• Could I instead define the boxes as styles?
• The spacing is manually adjusted, and very ugly code..
• I was not able to place the text in the bottom right
• How can I make it so the last box takes up the remaining space of the page?

Here is my code

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usepackage{xcolor}

\definecolor{maincolorLight}{HTML}{838fbc}
\definecolor{maincolorMedium}{HTML}{425b9b}
\definecolor{maincolorDark}{HTML}{003d80}

\title{atEndTikz}
\author{Øistein Søvik}
\date{May 2019}

\begin{document}

\noindent\pagestyle{empty}
\pgfmathsetmacro{\myscale}{\textwidth/18.85cm}%
\begin{tikzpicture}[nodes={inner sep=0pt,outer sep=0pt},scale=\myscale]
\fill[maincolorDark]  (0,0) rectangle (18.85,3.25);
\begin{scope}[shift={(0,-3.5)}]
\fill[maincolorMedium]  (0,0) rectangle (18.85,3.25);
\end{scope}
\begin{scope}[shift={(0,-26)}]
\fill[maincolorLight]  (0,0) rectangle (18.85,22.25);
\end{scope}
\end{tikzpicture}

\end{document}


With tikzpagenodes you can fill to the bottom right corner of the text area.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikzpagenodes}

\definecolor{maincolorLight}{HTML}{838fbc}
\definecolor{maincolorMedium}{HTML}{425b9b}
\definecolor{maincolorDark}{HTML}{003d80}

\title{atEndTikz}
\author{Øistein Søvik}
\date{May 2019}

\begin{document}

\noindent\pagestyle{empty}%
\pgfmathsetmacro{\myscale}{\textwidth/18.85cm}%
\begin{tikzpicture}[scale=\myscale,remember picture,overlay]
\path (current page text area.south east) coordinate (BR);
\fill[maincolorDark]  (0,0) rectangle (0,-3.25-|BR);
\fill[maincolorMedium]  (0,-3.5) rectangle (0,-3.5-3.25-|BR);
\fill[maincolorLight]  (0,-7) rectangle (BR);
\end{tikzpicture}
\clearpage
\end{document}


If you used \myscale only to get the width of the rectangles right, you could remove it, then of course the vertical dimensions get unscaled as well. And there is the possibility to define as style for the rectangles using insert path but I am not sure what it buys you in this case.

You may want to use the baseline option if you want to fill more:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{tikzpagenodes}

\definecolor{maincolorLight}{HTML}{838fbc}
\definecolor{maincolorMedium}{HTML}{425b9b}
\definecolor{maincolorDark}{HTML}{003d80}

\title{atEndTikz}
\author{Øistein Søvik}
\date{May 2019}

\begin{document}

\noindent\pagestyle{empty}%
\pgfmathsetmacro{\myscale}{\textwidth/18.85cm}%
\begin{tikzpicture}[scale=\myscale,remember
picture,overlay,baseline=-\baselineskip]
\path (current page text area.south east) coordinate (BR);
\fill[maincolorDark]  (0,0) rectangle (0,-3.25-|BR);
\fill[maincolorMedium]  (0,-3.5) rectangle (0,-3.5-3.25-|BR);
\fill[maincolorLight]  (0,-7) rectangle (BR);
\end{tikzpicture}
\clearpage
\end{document}


• Using your solution with \usepackage[showframe]{geometry} gives me this i.imgur.com/ZUvcjiE.png. It manages to perfectly align at the bottom and right. Why is there some gap to the left and at the top? Btw great solution. – N3buchadnezzar May 31 '19 at 14:33
• @N3buchadnezzar If you replace \noindent\pagestyle{empty} by \noindent\pagestyle{empty}%, i.e. add a % the horizontal space goes away. The vertical space is because you sit at the base line of a text line. Do you want the vertical space to be removed, too? If so, you need to add ,baseline=-\baselineskip. I added a version that does this. – user121799 May 31 '19 at 14:41
• Perfect! I tried to fix it by adding \path (current page text area.north west) coordinate (TL); but your solution is more clever! – N3buchadnezzar May 31 '19 at 14:47
• @N3buchadnezzar If you always want to fill the full page, your proposal is better IMHO. (I thought you may eventually only fill the rest of the page like this.) – user121799 May 31 '19 at 14:49