[Tex/LaTex] Use of optional argument stretch in \parbox

boxesoptional argumentsspacing

I'm having some difficulty on how to use the "stretch" optional argument of \parbox. Is it supposed to equally interspace lines of text inside a box of determined size?

If I code it like:

\documentclass{article}
\begin{document}
  Text
  \fbox{\parbox[c][15cm][s]{5cm}{I want to stretch this text inside this box}}
\end{document}

This is the outcome I get:
Example1

I also experimented with \parbox and got some unexpected outcomes. In the following code, I merely deleted the alignment optional argument (default is center) from the previous test:

\documentclass{article}
\begin{document}
Text
\fbox{\parbox[15cm][s]{5cm}{I want to stretch this text inside this box}}
\end{document}

As a result, this came out:
Example2

Which confused me, because I thought deleting the first optional argument would simply put it in default. I also didn't get why the text from the mandatory argument was substituted by the letter "s", a shortcut for "stretch" in the third optional argument.

Another test:

\documentclass{article}
\begin{document}
Text
\fbox{\parbox[15cm]{5cm}{I want to stretch this text inside this box}}
\end{document}

Which yielded me:
Example3

In this last one, I deleted the stretch optional argument, but the height of the box was not drawn.

Why did I get those results? I'm barely a starter at TeX, so might me missing obvious points on the use of optional arguments.

Best Answer

With

\parbox[c][3cm][s]{5cm}{I want to stretch this text inside this box}

there is no stretchable glue in the box and indeed you get the warning

Underfull \vbox (badness 10000) detected

If you want that the first line is at the top and the second line at the bottom, you need to make the interline glue stretchable:

\documentclass{article}

\begin{document}
\fbox{\parbox[c][3cm][s]{5cm}{
  \setlength{\baselineskip}{1\baselineskip plus 1fil}
  I want to stretch this text inside this box
}}
\end{document}

enter image description here

In order to specify the second (and third) optional argument, you must specify the first. So

\parbox[3cm]{5cm}{...}

gives the same result as \parbox{5cm}{...}; unfortunately LaTeX doesn't do a check for the contents of the first optional argument, which should only be c (default), t or b. If it's different from any of these, it's silently ignored.

If you don't specify the third optional argument, it defaults to be the same as the first.

Related Question