# Adjust minipage to fill remaining vertical space

I am trying to divide a document in three parts by using minipages. First, I created a top strip and after it I want to separate the document in two parts and make it so those parts fill completely the remaining vertical spacing of the page

My problem is that I have to manually calculate the height of the second and third minipages, so they fill the whole page. Is it possible to automatize this, so if I change the height of the top strip they will be automatically modified?

Code:

% Heavily commented to hopefully undestand what I am doing (Help!)
%

% Start a document with the here given default font size and paper size.
\documentclass[10pt,a4paper]{article}

% Call needed packages
\usepackage[a4paper,margin=0pt]{geometry} % Set the page margins.
\usepackage{lipsum} % To create random text
\usepackage{fontspec}
\usepackage{xcolor}

% Setup the language.
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\hyphenation{Some-long-word}

%Colors used
\definecolor{babyblueeyes}{rgb}{0.63, 0.79, 0.95}
\definecolor{blizzardblue}{rgb}{0.67, 0.9, 0.93}

% Command to check margins
\newcommand\redbox[1]{%
\setlength\fboxsep{0pt}\fcolorbox{red}{white}{#1}
}

\begin{document}

%--- TOP STRIP ---%
\noindent % Delete indentation white space
\colorbox{babyblueeyes}{% Background color
\begin{minipage}[c][0.65in]{\textwidth}% Height and width of minipage
\centering
\textcolor{black}{\fontsize{14pt}{0pt}%
\textbf{John Doe Peter}}
\\ \medskip
\textcolor{white}{\fontsize{14pt}{0pt}%
\textbf{Evolving Latex apprentice}}
\end{minipage}
}
%
%--- LEFT STRIP ---%
\noindent
\colorbox{blizzardblue}{% Background color
\begin{minipage}[t][10in]{0.2\textwidth}% Height and width of minipage
\vspace{0pt}
\textcolor{black}{\fontsize{14pt}{0pt}%
\textbf{Title side strip}}
\\ \medskip
\textcolor{white}{\fontsize{14pt}{0pt}%
\textbf{Text side strip}}
\end{minipage}%
}%
%
%--- RIGHT PART ---%
\begin{minipage}[t][8in]{0.75\textwidth}%
\vspace{0pt}
\lipsum[1-5]
\end{minipage}

\end{document}

• There will be no automatic page breaks this way. Are you sure you want to do it this way? You could set up the margins correctly and change the titling macros to print into your title-margin. – Skillmon likes topanswers.xyz Oct 8 '19 at 10:28
• And you mistyped \LaTeX in your header. – Skillmon likes topanswers.xyz Oct 8 '19 at 10:29
• Or are you referring to the product made from the rubber tree's juice? – Skillmon likes topanswers.xyz Oct 8 '19 at 10:29
• @Skillmon Thanks for the \LaTeX typo! I forgot to write it properly. I was able to find a solution to my question, posting it right now – Jes Oct 8 '19 at 10:40
• @Skillmon I dont know how to do that, but this is intended to be a single page document, so I don't think I need page breaks. Your comment is because minipage does not support page breaks, right? – Jes Oct 8 '19 at 10:53

I found a solution. Credits are due to user @KOLEYGR.

The code used is as follows. The -0.2in present in calculateBottomStripHeight was chosen manually, I guess it's a value coming from some sort of internal padding or margin present in minipage or colorbox, but I was not able to remove it programatically.

\newlength{\availafter}
\newlength{\topstripheight} % Top strip height
\setlength{\topstripheight}{0.65in}
\def\calculateBottomStripHeight{%
\setlength{\availafter}{%
\the\dimexpr\textheight-0.2in-\topstripheight-\pagetotal\relax}}


After this, I just use \topstripheight for the top strip and then I call \calculateBottomStripHeight and use \avaliafter as the height for the other two minipages. I have tested it and it seems to work properly.

Full code:

% Start a document with the here given default font size and paper size.
\documentclass[10pt,a4paper]{article}

% Call needed packages
\usepackage[a4paper,margin=0pt]{geometry} % Set the page margins.
\usepackage{lipsum} % To create random text
\usepackage{fontspec}
\usepackage{xcolor}

% Setup the language.
\usepackage[english]{babel}
\hyphenation{Some-long-word}

%Colors used
\definecolor{babyblueeyes}{rgb}{0.63, 0.79, 0.95}
\definecolor{blizzardblue}{rgb}{0.67, 0.9, 0.93}

% Command to check margins
\newcommand\redbox[1]{%
\setlength\fboxsep{0pt}\fcolorbox{red}{white}{#1}
}

% Set top strip height and remaining space
% Credits to KOLEYGR
\newlength{\availafter}

\newlength{\topstripheight} % Top strip height
\setlength{\topstripheight}{0.65in}

\def\calculateBottomStripHeight{%
\setlength{\availafter}{%
\the\dimexpr\textheight-0.2in-\topstripheight-\pagetotal\relax}}

\begin{document}

%--- TOP STRIP ---%
\noindent % Delete indentation white space
\colorbox{babyblueeyes}{% Background color
\begin{minipage}[c][\topstripheight]{\textwidth}% Height and width of minipage
\centering
\textcolor{black}{\fontsize{14pt}{0pt}%
\textbf{John Doe Peter}}
\\ \medskip
\textcolor{white}{\fontsize{14pt}{0pt}%
\textbf{Evolving \LaTeX{} apprentice}}
\end{minipage}
}
\calculateBottomStripHeight
%--- LEFT STRIP ---%
\noindent
\colorbox{blizzardblue}{% Background color
\begin{minipage}[t][\availafter]{0.2\textwidth}% Height and width of minipage
\vspace{0pt}
\textcolor{black}{\fontsize{14pt}{0pt}%
\textbf{Title side strip} Jesús María y José}
\\ \medskip
\textcolor{white}{\fontsize{14pt}{0pt}%
\textbf{Text side strip}}
\end{minipage}%
}%
%
%--- RIGHT PART ---%
\begin{minipage}[t][\availafter]{0.75\textwidth}%
\vspace{0pt}
\lipsum[1-5]
\end{minipage}

\end{document}

• Thanks for the credit (+1 for informing that the problem is resolved and answering your question instead of leaving it unanswered). – koleygr Oct 8 '19 at 10:58
• Hey, I do not know why but your answer dissapeared. It was a good solution and the auto-adjusting feature is amazing! Only thing that did not work was that it only worked with 0.65in as top strip height. I think the problem was that there was a \the missing before \dimexpr. At least, after adding it, it works perfectly! Thanks again :) – Jes Oct 8 '19 at 11:01
• Welcome ... I found some problems while testing and I had to delete the answer till test again and add a real solution ... Actually I could not understand (can't yet) why if I add inner sep=0 and outer sep=0 in the minipages (so, that your manual adjustment will not be needed) I can't use in the same time t or b or c optional argument in the minipage. (The answers I used are here: tex.stackexchange.com/a/396216 and here: tex.stackexchange.com/a/511034) – koleygr Oct 8 '19 at 11:16