# Unwanted line break with \raggedleft, \centering or \raggedright

In the following example, I get unwanted line breaks for text "Dest-Addr". The result is correct for text "Hello-World". The result is also correct if I change font size to 10pt or 12pt.

\documentclass[11pt]{article}
\parindent=0pt
\begin{document}

\setbox0=\hbox{Hello-World}
\setbox2=\vbox{\hsize=\wd0 Hello-World} \box2
\setbox2=\vbox{\hsize=\wd0 \raggedright Hello-World} \box2
\setbox2=\vbox{\hsize=\wd0 \centering Hello-World}   \box2
\setbox2=\vbox{\hsize=\wd0 \raggedleft Hello-World}  \box2

\end{document}


1. Where do these unwanted line breaks come from?
2. How can I get rid of these line breaks?

I need to use \raggedleft, \centering and \raggedright since in my package I need to compare and get the minimal width of several text lines and put them in a vbox (similar to varwidth package). Also I can not put them in a hbox for some other reasons.

• I get no linebreaks with pdftex texlive 2021 nor with luatex, but I do with xetex Jun 5, 2021 at 9:45

This only happens with xetex it seems.

You can prevent hyphenation by setting the exhyphenpenalty to the maximumn

\documentclass[11pt]{article}
\parindent=0pt
\begin{document}

\setbox0=\hbox{Hello-World}
\setbox2=\vbox{\hsize=\wd0 Hello-World} \box2
\setbox2=\vbox{\hsize=\wd0 \raggedright Hello-World} \box2
\setbox2=\vbox{\hsize=\wd0 \centering Hello-World}   \box2
\setbox2=\vbox{\hsize=\wd0 \raggedleft Hello-World}  \box2


• @L.J.R. with \raggedright you don't (normally) get hyhpenation unless the word is longer than the text width so stopping hyphenation may not be an issue Jun 5, 2021 at 11:45