I'm trying to get a "contact sheet" where identically sized boxes are laid out next to each other without any whitespace. As my goal is to use this in a generated document, and as the number of items is unknown in advance, I'd like to avoid tabular-like approaches and rely on native line breaking and page breaking machinery. This is also an experiment to learn more about the internals of tex/latex, so along the way I also played a lot with keywords like badness, emergencystretch, sloppy etc. But in the end, my quest can be summed up in the code below.
My first try below obviously produces some "interword" whitespace between boxes, so it is not desirable.
In my second try (page 2) I explicitely remove this whitespace but this also removes line breaks. I don't really understand what's going on.
In my third try (page 3) I explicitely tell (la)tex that it's ok to break lines, and I get the result I want w.r.t. horizontal whitespace. But still, there is some amount of vertical whitespace between lines, and this whitespace occupies room. As a result, the blue box ends up on page four, when I want it to be on on page three.
This is my question: how do I get rid of that small vertical whitespace between two consecutive lines of text ?
\documentclass[a4paper]{article}
\usepackage[
text={15cm,21cm},
showframe,
]
{geometry}
\usepackage{xcolor}
\setlength{\parindent}{0pt}
\begin{document}
% page 1
\textcolor{red}{\rule{5cm}{7cm}}
\textcolor{green}{\rule{5cm}{7cm}}
\textcolor{red}{\rule{5cm}{7cm}}
\textcolor{green}{\rule{5cm}{7cm}}
\textcolor{red}{\rule{5cm}{7cm}}
\textcolor{green}{\rule{5cm}{7cm}}
\newpage
% page 2
\textcolor{green}{\rule{5cm}{7cm}}%
\textcolor{red}{\rule{5cm}{7cm}}%
\textcolor{green}{\rule{5cm}{7cm}}%
\textcolor{red}{\rule{5cm}{7cm}}%
\newpage
% page 3
\textcolor{green}{\rule{5cm}{7cm}}\linebreak[0]%
\textcolor{red}{\rule{5cm}{7cm}}\linebreak[0]%
\textcolor{green}{\rule{5cm}{7cm}}\linebreak[0]%
\textcolor{red}{\rule{5cm}{7cm}}\linebreak[0]%
\textcolor{green}{\rule{5cm}{7cm}}\linebreak[0]%
\textcolor{red}{\rule{5cm}{7cm}}\linebreak[0]%
\textcolor{blue}{\rule{5cm}{7cm}}\linebreak[0]%
\textcolor{red}{\rule{5cm}{7cm}}\linebreak[0]%
\textcolor{green}{\rule{5cm}{7cm}}\linebreak[0]%
\end{document}