I am generating a bunch of documents with centered titles of varying lengths. Sometimes the titles run onto a second line. When they do so, I would rather have the line break occur somewhere in the middle so that the two lines have approximately equal lengths. But, as far as I can tell, LaTeX does not allow this because it results in underfull hboxes.
Is there a way to dynamically change the width of the hbox to be as narrow as possible for a given number of lines (e.g. once there is a second line, reduce the hbox as much as possible without creating a third line)?
Note: This is a different problem than the one discussed in "How can I make (La)TeX prefer to fill centered lines" because this is about changing the width of the lines to be filled rather than having those widths decrease from line to line. I also tried the varwidth package without success.
\documentclass{article}
\begin{document}
\begin{center}
\LARGE \bfseries
This is a short title.\
~\
This is a longer one-line title.\
~\
This is a longer title that runs onto two lines.\
~\
% I would rather it look like this
\begin{minipage}{3in}
\centering
This is a longer title that runs onto two lines.\
\end{minipage}
\end{center}
\end{document}