5

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.

1
  • I forgot to add “Welcome to TeX.SX!” when answering.
    – egreg
    Jan 20, 2014 at 13:35

2 Answers 2

7

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.

2
  • But in my second example, \fbox{\parbox[15cm][s]{5cm}{I want to stretch this text inside this box}} should then yield the same outcome as \parbox{5cm}{...} because I did not specify the first optional argument. However, what I got was the substitution of the text from the mandatory argument for s.
    – PPA
    Jan 20, 2014 at 13:23
  • 1
    @PPA With \parbox[15cm][s]{5cm}{I want...} you get an error message; then the output is whatever LaTeX has been able to recover, probably different from what you had in mind.
    – egreg
    Jan 20, 2014 at 13:25
3

There are a lot of questions there;-)

Is it supposed to equally interspace lines of text inside a box of determined size?

No, it simply doesn't add any glue itself so it relies on any strech glue within the content to fill the required space,

Which confused me, because I thought deleting the first optional argument

You didn't delete the first optional argument, you changed its value from c to 15cm.

4
  • Since the questions were all related, I thought separating them in different posts would be redundant. I'm completely unfamiliar with the term glue in TeX, but it makes sense. I'll look into it.
    – PPA
    Jan 20, 2014 at 13:28
  • 1
    @PPA the LaTeX book calls stretchable space a "rubber length" but the TeXbook calls it glue (and TeX's logging output and primitive commands call it skip) but most people call it glue Jan 20, 2014 at 13:30
  • @David what's the default value of the optional agument <height> in \parbox when this arg is not given?
    – lyl
    Feb 20, 2019 at 2:35
  • @lyl please do not ask questions as comments on old answers. not using the option is not equivalent to using any value with the option, it takes a different code path. just as in te horizontal case \makebox{zzz} is not equivalent to \makebox[...]{zzz} for any value of ... Feb 20, 2019 at 8:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .