You're wondering why there's more vertical space before than after the unbreakable text, right?

Ulrike told you a good way to deal with it, I'd like to explain a bit why this happens. The problem is indeed the somewhat unfortunate definition of the center
environment. This starts with \trivlist\centering\item\relax
, so it uses the \centering
command inside a trivial list. Now \item
places an (empty) label as the first object to be centered, and your unbreakable text doesn't fit on the line, so TeX decides to put it on the next line. You can visualize this by redefining \trivlist
so that the label isn't empty anymore:

Note that the LABEL
isn't centered since I defined it so that it sticks out to the left.
\documentclass{article}
\makeatletter
\def\trivlist{%
\parsep\parskip
\@nmbrlistfalse
\@trivlist
\labelwidth\z@
\leftmargin\z@
\itemindent\z@
%\let\@itemlabel\@empty
\def\@itemlabel{\llap{LABEL}}
\def\makelabel##1{##1}}
\makeatother
\begin{document}
\noindent left \hfill right
\begin{center}
\texttt{a~sentence~that~is~not~so~long}
\end{center}
\noindent left \hfill right
\begin{center}
\texttt{a~sentence~that~is~long~and~continues~with~the~reason~so~that~it~sticks~out~a~bit}
\end{center}
\noindent left \hfill right
\end{document}
I think you're safe if you redefine the center
environment to use Ulrike's suggestion. Note the \begingroup
and \endgroup
!
\renewenvironment{center}{\begingroup\par\bigskip\centering}{\par\bigskip\endgroup}
center
is one) add space before and after them.center
environment (which of course also occurs without long unbreakable text). The question is why there's additional space only before the environment! (So no, it's not a duplicate of that other question.)