I try to place 2 boxes on top of each other. I would like to define the height of the lower box and a potential gap between the boxes and the top box should use the remaining space.
As you can see in the reprex, there is still a tiny small line between (and I cannot judge whether the blue box is indeed spanning the full space). Trial and error told me that the line is about 1pt
wide.
My approach was:
- Determine height of the top box as follows:
- Use the full text height
- Substract the height of the lower box and the intended gap (here
0pt
to highlight the issue) - Eventually substract 4 times
fboxsep
to account for the additional distance between box and text in both boxes.
- Create a gap via
vspace
(again, here the gap is0pt
) - Place the lower box with the given height.
I would be curious to know which length LaTeX
is adding to adjust my vspace
command accordingly. Expected outcome is that the lower box sits on the edge and that the height of the upper box is calculated, i.e. all the space available minus gap and lower box height.
Reprex
\documentclass{article}
\usepackage{xcolor}
\usepackage[a4paper,margin=0pt]{geometry}
\newlength{\mytopboxheight}
\newlength{\mybottomboxheight}
\newlength{\myskip}
\newlength{\myboxwidth}
\setlength{\mybottomboxheight}{40pt}
\setlength{\myskip}{0pt}
\setlength{\mytopboxheight}{\dimexpr\textheight-\mybottomboxheight-4\fboxsep-\myskip\relax}
\setlength{\myboxwidth}{\dimexpr\textwidth-2\fboxsep\relax}
\begin{document}
\noindent%
\colorbox{orange}{%
\makebox(\myboxwidth,\mytopboxheight){%
\the\fboxsep%
}%
}%
\vspace{\myskip}%
\par\noindent%
\colorbox{blue}{%
\makebox(\myboxwidth,\mybottomboxheight){%
A%
}%
}%
\end{document}