Which length still creates the distance between the 2 boxes

boxeslengthsmiktexvertical alignment

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:

  1. Determine height of the top box as follows:
    1. Use the full text height
    2. Substract the height of the lower box and the intended gap (here 0pt to highlight the issue)
    3. Eventually substract 4 times fboxsep to account for the additional distance between box and text in both boxes.
  2. Create a gap via vspace (again, here the gap is 0pt)
  3. 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}

enter image description here

Best Answer

That's \lineskip kicking in.

\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%
  }%
}

\nointerlineskip

\noindent
\colorbox{blue}{%
  \makebox(\myboxwidth,\mybottomboxheight){%
    A%
  }%
}
\end{document}

enter image description here

Related Question