Geometry affects line breaking
geometry
changes the page size unless you use options to prevent that,
\documentclass{article}
\showthe\textwidth
\usepackage{geometry}% works when commented out
\showthe\textwidth
\newcommand{\block}{\rule{0.5\textwidth}{1pt}\allowbreak}
\parindent=0pt
\begin{document}
\block
\block
\block
\block
\end{document}
You see the same without geometry
but with the same page width
\documentclass{article}
\textwidth=430.00462pt
\newcommand{\block}{\rule{0.5\textwidth}{1pt}\allowbreak}
\parindent=0pt
\begin{document}
\block
\block
\block
\block
\end{document}
In either case, due to rounding errors, you can't fit two blocks exactly filling a line.....
According to TeX, 0.5\textwidth+0.5\textwidth
may not be equal to \textwidth
.
When geometry
sets the text width to 430.00462pt, this is precisely what happens. The sum of the widths of two rules falls 1sp short of the textwidth and TeX tries to stick another rule in the first line, having no stretchability available.
However, you can do more accurate computations:
\documentclass{article}
\usepackage{geometry}% works when commented out
\usepackage{xfp}
\newcommand{\block}{\rule{\fpeval{0.5\textwidth}pt}{1pt}\allowbreak}
\parindent=0pt
\begin{document}
\block
\block
\block
\block\unpenalty % to avoid the spurious underfull box message
\bigskip
\begin{tabular}[t]{llll}
Method & half & half + half & text width\\
\hline
\TeX & \the\dimexpr 0.5\textwidth\relax & \the\dimexpr 0.5\textwidth + 0.5\textwidth\relax &
\the\textwidth \\
l3fp & \fpeval{0.5\textwidth}pt & \fpeval{0.5\textwidth+0.5\textwidth}pt
\end{tabular}
\end{document}
The length 0.5\textwidth
, according to TeX is 14090391sp, whereas the text width is 28180783.
You can solve the issue by defining the rule differenly:
\documentclass{article}
\usepackage{geometry}% works when commented out
\newcommand{\block}{\rule{0.5\textwidth}{1pt}\allowbreak\hspace{0pt plus 1sp}}
\parindent=0pt
\begin{document}
\block
\block
\block
\block
\end{document}
Another famous case: if you try
\setbox0=\hbox to 2in{\hskip 1in \hskip 1in}
you'll get Underfull \hbox (badness 10000)
because two one inch skips fall 1sp short of two inches.