Next: Making paragraphs, Previous: Counters, Up: Top [Contents][Index]

A *length* is a measure of distance. Many LaTeX commands take a
length as an argument.

Lengths come in two types. A *rigid length* such as `10pt`

does not contain a `plus`

or `minus`

component. (Plain TeX
calls this a *dimen*.) A *rubber length* (what Plain TeX
calls a *skip*) such as as with `1cm plus0.05cm minus0.01cm`

can contain either or both of those components. In that rubber length,
the `1cm`

is the *natural length* while the other two, the
`plus`

and `minus`

components, allow TeX to stretch or
shrink the length to optimize placement.

The illustrations below use these two commands.

% make a black bar 10pt tall and #1 wide \newcommand{\blackbar}[1]{\rule{#1}{10pt}} % Make a box around #2 that is #1 wide (excluding the border) \newcommand{\showhbox}[2]{% \fboxsep=0pt\fbox{\hbox to #1{#2}}}

This example uses those commands to show a black bar 100 points
long between ‘`XXX`’ and ‘`YYY`’. This length is rigid.

XXX\showhbox{100pt}{\blackbar{100pt}}YYY

As for rubber lengths, shrinking is simpler one: with ```
1cm minus
0.05cm
```

, the natural length is 1cm but TeX can shrink it down
as far as 0.95cm. Beyond that, TeX refuses to shrink any more.
Thus, below the first one works fine, producing a space of
98 points between the two bars.

XXX\showhbox{300pt}{% \blackbar{101pt}\hspace{100pt minus 2pt}\blackbar{101pt}}YYY XXX\showhbox{300pt}{% \blackbar{105pt}\hspace{100pt minus 1pt}\blackbar{105pt}}YYY

But the second one gets a warning like ‘`Overfull \hbox (1.0pt too
wide) detected at line 17`’. In the output the first ‘`Y`’ is
overwritten by the end of the black bar, because the box’s material is
wider than the 300pt allocated, as TeX has refused to shrink
the total to less than 309 points.

Stretching is like shrinking except that if TeX is asked to stretch beyond the given amount, it will do it. Here the first line is fine, producing a space of 110 points between the bars.

XXX\showhbox{300pt}{% \blackbar{95pt}\hspace{100pt plus 10pt}\blackbar{95pt}}YYY XXX\showhbox{300pt}{% \blackbar{95pt}\hspace{100pt plus 1pt}\blackbar{95pt}}YYY

In the second line TeX needs a stretch of 10 points and only
1 point was specified. TeX stretches the space to the required
length but it gives you a warning like ‘`Underfull \hbox (badness
10000) detected at line 22`’. (We won’t discuss badness.)

You can put both stretch and shrink in the same length, as in
`1ex plus 0.05ex minus 0.02ex`

.

If TeX is setting two or more rubber lengths then it allocates the stretch or shrink in proportion.

XXX\showhbox{300pt}{% \blackbar{100pt}% left \hspace{0pt plus 50pt}\blackbar{80pt}\hspace{0pt plus 10pt}% middle \blackbar{100pt}}YYY % right

The left and right bars take up 100 points, so the middle needs
another 100. The middle bar is 80 points so the two
`\hspace`

’s must stretch 20 points. Because the two are
`plus 50pt`

and `plus 10pt`

, TeX gets 5/6 of the stretch
from the first space and 1/6 from the second.

The `plus`

or `minus`

component of a rubber length can contain
a *fill* component, as in `1in plus2fill`

. This gives the
length infinite stretchability or shrinkability so that TeX could set
it to any distance. Here the two figures will be equal-spaced across
the page.

\begin{minipage}{\linewidth} \hspace{0pt plus 1fill}\includegraphics{godel.png}% \hspace{0pt plus 1fill}\includegraphics{einstein.png}% \hspace{0pt plus 1fill} \end{minipage}

TeX actually has three levels of infinity for glue components:
`fil`

, `fill`

, and `filll`

. The later ones are more
infinite than the earlier ones. Ordinarily document authors only use
the middle one (see \hfill and see \vfill).

Multiplying a rubber length by a number turns it into a rigid length, so
that after `\setlength{\ylength}{1in plus 0.2in}`

and
`\setlength{\zlength}{3\ylength}`

then the value of
`\zlength`

is `3in`

.

• Units of length: | The units that LaTeX knows. | |

• \setlength: | Set the value of a length. | |

• \addtolength: | Add a quantity to a length. | |

• \settodepth: | Set a length to the depth of something. | |

• \settoheight: | Set a length to the height of something. | |

• \settowidth: | Set a length to the width of something. |