Last chapter discussed the various ways you can add or remove extra space at any moment. This chapter will talk about the other side of that coin: the basic lengths that are applied throughout the whole document.

Dimensions

There’s something you need to understand about dimensions in LaTeX. Each block/environment is a box with dimensions. These dimensions are width, height and depth.

  • The width is easy: how wide something is.
  • The height is the length of the part that is above the baseline.
  • The depth is the length of the part below the baseline.

The baseline is the imaginary line on which all letters sit. The image explains this better, I think.

Explanation of how LaTeX sees dimensions: width, height (above baseline), depth (below baseline)
Explanation of how LaTeX sees dimensions: width, height (above baseline), depth (below baseline)

Getting Lengths

Often, you want everything to line up correctly, and similar things to be of similar size. This can be done by accessing LaTeX’s default lengths. These are:

CommandDescription
\baselineskipThe normal vertical distance between two lines in a paragraph
\baselinestretchMultiplies \baselineskip
\columnsepThe distance between columns
\columnwidthThe width of a column
\evensidemarginThe margin for ’even’ pages
\oddsidemarginThe margin for ‘odd’ pages
\linewidthThe width of a line (in the local environment)
\paperwidthThe width of the page
\paperheightThe height of the page
\parindentThe regular paragraph indentation
\parskipThe extra vertical space between two paragraphs
\tabcolsepThe default separation between columns in a tabular environment
\textheightThe height of the text
\textwidthThe width of the text
\topmarginThe size of the top margin
\unitlengthUnits of length in the picture environment
\leftskipExtra left margin for a single complete paragraph (0pt by default)
\rightskipExtra right margin for a single complete paragraph (0pt by default)
1A regular paragraph here, with regular built-in lengths set and not changed.
2
3\setlength{\leftskip}{20pt} \setlength{\rightskip}{20pt} A not-so-regular paragraph here, with space being skipped on the left and right side, leading to a smaller width.
Code left > output right
Code left > output right

The \baselinestretch command is mostly semantical. By default, the multiplication factor is just 1.0, but if you want to change this vertical line spacing, you need to renew this command.

You can multiply numbers by these lengths, simply by using it in place of a unit.

1A regular paragraph here, with regular built-in lengths set and not changed.
2
3\setlength{\parskip}{0.25\textwidth} A not-so-regular paragraph here, with lots of skipped vertical space between itself and the previous paragraph.
Code left > output right
Code left > output right

If you want to only print the value, use \the in front of it. (Just like with counters, remember?)

1The width of the text in this document is: \the\textwidth
Code left > output right
Code left > output right

One very important use case of this length system, is with the \hspace and \vspace commands. Instead of putting in a standard length as argument, they can also use so-called skip arguments:

1default value plus stretch value minus shrink value

It always tries to use the default value. But, if a box is overfull, it will shrink the whitespace (but never more than the value you provided). If a box is underfull, it will stretch the whitespace (but never more than the value you provided). This doesn’t work for other commands—they ignore the plus and minus, and see them as text to put in the document.

Setting Lengths

As you’ve seen by now, lengths share many similarities with counters. Many defaults exist, but you can set, override and increment them. Next section you’ll also learn how to create your own.

As such, you can override these lengths and set your own if you want. To set a completely new length, use

1\setlength{command}{newLength}

If you want to add or subtract something from the current value, use

1\addtolength{command}{incrementAmount}

Another way of setting a length, is by using those dimensions I just introduced. These commands set the length to the width, height or depth of the text block you input.

1\settowidth{command}{text} \settoheight{command}{text} \settodepth{command}{text}
1\settoheight{\parskip}{\Huge M} First paragraph
2
3Second Paragraph
Code left > output right
Code left > output right

Creating Lengths

It’s possible to define your own lengths. This way, you define values ones and reuse them throughout the document!

You can change this value any time you like, and everything will automatically be updated accordingly. The syntax is

1\newlength{command}

This will set command to a zero length (more specifically, 0in). This means you still need a \setlength right after it, to set it to the value you want.

1\newlength{\myLength}
2\setlength{\myLength}{5pt}
3
4Our own length is: \the\myLength \par
5
6\addtolength{\myLength}{0.5\linewidth} Our own length is: \the\myLength
Code left > output right
Code left > output right

Rubber Lengths

All these lengths so far have been exact. But, sometimes, you don’t know upfront what length you’re looking for.

That’s when so-called rubber lengths come into play.

A rubber length is created with the \stretch{factor} command. If there’s no other rubber length in the line, it will just fill up all leftover white space. If there are other commands competing for the space, it will scale in accordance with its factor.

1Some text \hspace{\stretch{3}} More text \hspace{\stretch{1}} End of line!
Code left > output right
Code left > output right

Alternatively, the \fill command is the same as \stretch{1}.

Looking Back on Lists

This section on spacing and lengths started with the question: “is there an easy way to change the amount of space between list items?”

Now we can answer it. Find the name of the length LaTeX uses by default: it’s \itemsep. Simply change that length!

1\begin{itemize}
2    \setlength{\itemsep}{20pt}
3    \item Uno
4    \item Duo
5    
6    \setlength{\itemsep}{5pt}
7    \item Tres
8\end{itemize}
Code left > output right
Code left > output right
Continue with this course
Support me and this website!

Want to support me?

Buy one of my projects. You get something nice, I get something nice.

Donate through a popular platform using the link below.

Simply giving feedback or spreading the word is also worth a lot.