# Automatically justify text in \parbox

The left part of the attached figure showes the nomal typeset of \parbox. The first/second lines are fully filled with words, and the rest words are bent to the third line. What interests me is: how to justify words of the last line autometically as shown on the right part of the attatched figure? Briefly speaking, add a option arg [s] to \parbox just like the \makebox does.

\documentclass{article}
%\usepackage{...}
\begin{document}

\parbox[s]{15em}{How to spread align the rest words which are not enough to fill the width of parbox?}% I just want the option arg of \parbox in this example works like \makebox[s] does.

\end{document}


There is nothing special about \parbox here, you see the same paragraph justification in the main page, normally the last line is allowed to be short but if you want that space to be 0pt you can set

\setlength\parfillskip{0pt}


As this makes it much harder to get a reasonable paragraph setting you probably should also use \sloppy to allow other spaces to stretch more to compensate.

\documentclass{article}
%\usepackage{...}
\begin{document}

\parbox{15em}{%
\sloppy\setlength\parfillskip{0pt}
How to spread align the rest words which are not
enough to fill the width of
parbox?}

\end{document}

• Sorry David, I don't quite understand your meaning. Would you please send a MWE illustrated how to get to the typeset I want? Thank you. – lyl Feb 17 at 9:41
• @lyl example added – David Carlisle Feb 17 at 9:46
• Great trick!! That's just what I nedd!! Many thanks! And where can I find descriptions about \sloppy and \parfillskip, because I don't konw how to use them? – lyl Feb 17 at 9:52
• @lyl \parfillskip is a tex primitive so the texbook or the free texbytopic, \sloppy should be in any basic latex tutorial, but offical documentation is the latex book, there are thousands of examples of both on this site – David Carlisle Feb 17 at 9:54
• After the use of \setlength\parfillskip{0pt} in \parbox, will it affect folloing paragraph ? – lyl Feb 17 at 10:32