Lengths (LaTeX2e unofficial reference manual (October 2018))

## Lengths

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

TeX and LaTeX know about these units both inside and outside of math mode.

`pt`

  Point, 1/72.27 inch. The conversion to metric units, to two decimal places, is 1point = 2.85mm = 28.45cm.

`pc`

  Pica, 12 pt

`in`

  Inch, 72.27 pt

`bp`

  Big point, 1/72 inch. This length is the definition of a point in PostScript and many desktop publishing systems.

`cm`

  Centimeter

`mm`

  Millimeter

`dd`

  Didot point, 1.07 pt

`cc`

  Cicero, 12 dd

`sp`

  Scaled point, 1/65536 pt

Two other lengths that are often used are values set by the designer of the font. The x-height of the current font ex, traditionally the height of the lowercase letter x, is often used for vertical lengths. Similarly em, traditionally the width of the capital letter M, is often used for horizontal lengths (there is also `\enspace`, which is `0.5em`). Use of these can help make a definition work better across font changes. For example, a definition of the vertical space between list items given as `\setlength{\itemsep}{1ex plus 0.05ex minus 0.01ex}` is more likely to still be reasonable if the font is changed than a definition given in points.

In math mode, many definitions are expressed in terms of the math unit mu given by 1 em = 18 mu, where the em is taken from the current math symbols family. See Spacing in math mode.

### `\setlength`

Synopsis:

    \setlength{len}{amount}

Set the length len to amount. The length name len must begin with a backslash, `\`. The `amount` can be a rubber length (see Lengths). It can be positive, negative or zero, and can be in any units that LaTeX understands (see Units of length).

Below, with LaTeX’s defaults the first paragraph will be indented while the second will not.

    I told the doctor I broke my leg in two places.

    \setlength{\parindent}{0em}
    He said stop going to those places.

If you did not declare len with `\newlength`, for example if you mistype the above as `\newlength{\specparindent}\setlength{\sepcparindent}{...}`, then you get an error like ‘`Undefined control sequence. <argument> \sepcindent`’. If you omit the backslash at the start of the length name then you get an error like ‘`Missing number, treated as zero. <to be read again> \relax l.19 \setlength{specparindent}{0.6\parindent}`’

### `\addtolength`

Synopsis:

    \addtolength{len}{amount}

Increment the length len by amount. The length name len begins with a backslash, `\`. The `amount` is a rubber length (see Lengths). It can be positive, negative or zero, and can be in any units that LaTeX understands (see Units of length).

Below, if `\parskip` starts with the value `0pt plus 1pt`

    Doctor: how is the boy who swallowed the silver dollar?
    \addtolength{\parskip}{1pt}

    Nurse: no change.

then it has the value `1pt plus 1pt` for the second paragraph.

If you did not declare the length len with `\newlength`, if for example you mistype the above as `\addtolength{\specparindent}{0.6\praindent}`, then you get something like ‘`Undefined control sequence. <argument> \praindent`’. If you leave off the backslash at the start of len, as in `\addtolength{parindent}{1pt}`, then you get something like ‘`You can't use `the letter p' after \advance`’.

### `\settodepth`

Synopsis:

    \settodepth{len}{text}

Set the length len to the depth of box that LaTeX gets on typesetting the text argument. The length name len must begin with a backslash, `\`.

This will show how low the character descenders go.

    \newlength{\alphabetdepth}
    \settodepth{\alphabetdepth}{abcdefghijklmnopqrstuvwxyz}
    \the\alphabetdepth

If you did not set aside the length len, if for example you mistype the above as `\settodepth{\aplhabetdepth}{abc...}`, then you get something like ‘`Undefined control sequence. <argument> \aplhabetdepth`’. If you leave the backslash out of len, as in `\settodepth{alphabetdepth}{...}` then you get something like ‘`Missing number, treated as zero. <to be read again> \setbox`’.

### `\settoheight`

Synopsis:

    \settoheight{len}{text}

Sets the length len to the height of box that LaTeX gets on typesetting the `text` argument. The length name len must begin with a backslash, `\`.

This will show how high the characters go.

    \newlength{\alphabetheight}
    \settoheight{\alphabetheight}{abcdefghijklmnopqrstuvwxyz}
    \the\alphabetheight

If no such length len has been declared with `\newlength`, if for example you mistype as `\settoheight{\aplhabetheight}{abc...}`, then you get something like ‘`Undefined control sequence. <argument> \alphabetheight`’. If you leave the backslash out of len, as in `\settoheight{alphabetheight}{...}` then you get something like ‘`Missing number, treated as zero. <to be read again> \setbox`’.

### `\settowidth`

Synopsis:

    \settowidth{len}{text}

Set the length len to the width of the box that LaTeX gets on typesetting the text argument. The length name len must begin with a backslash, `\`.

This measures the width of the lowercase ASCII alphabet.

    \newlength{\alphabetwidth}
    \settowidth{\alphabetwidth}{abcdefghijklmnopqrstuvwxyz}
    \the\alphabetwidth

If no such length len has been set aside, if for example you mistype the above as `\settowidth{\aplhabetwidth}{abc...}`, then you get something like ‘`Undefined control sequence. <argument> \aplhabetwidth`’. If you leave the backslash out of len, as in `\settoheight{alphabetwidth}{...}` then you get something like ‘`Missing number, treated as zero. <to be read again> \setbox`’.