> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/formatting/04-articles-how-to-change-paragraph-spacing-in-latex.md).

# Paragraph formatting

## Introduction

This article explores two methods of making changes to various aspects of paragraph spacing:

* the best practice, and recommended, method of using LaTeX packages such as [`setspace`](https://ctan.org/pkg/setspace) and [`parskip`](https://ctan.org/pkg/parskip) which provide options and user-level commands to change the spacing of your LaTeX documents;
* use of low-level TeX/LaTeX *parameter commands* to modify paragraph spacing. Direct use of parameter commands can bypass checks or controls provided by carefully crafted LaTeX packages, potentially resulting in unexpected consequences/side-effects elsewhere in your LaTeX document, so use them with care...

### Jump to sections of interest

Readers looking for quick solutions:

* go to the section [*Using LaTeX packages: setspace and parskip*](#using-latex-packages-setspace-and-parskip)

Readers interested in low-level commands:

* go to the sections [*TeX/LaTeX parameter commands*](#using-texlatex-parameter-commands) and [*The fundamentals: parameter commands and examples*](#the-fundamentals-parameter-commands-and-examples)

Readers interested in the fine details of line space calculations and paragraph structure:

* go the section [*Paragraph structure and line space calculations*](#paragraph-structure-and-line-space-calculations)

## Using LaTeX packages: setspace and parskip

* [The parskip package](#the-parskip-package)
* [The setspace package](#the-setspace-package)

### The parskip package

The [`parskip` package](https://ctan.org/pkg/parskip?lang=en) helps you safely change the space inserted between paragraphs in your document. It is designed to ensure that document structures such as table of contents, list environments and display headings are not adversely affected by a non-zero value of the [`\parskip` command](#parskip-tex-primitive), which is used to set the amount of space TeX/LaTeX inserts between paragraphs.

The `parskip` package doesn’t provide any user-level commands; instead, it uses package options to configure its actions. The [`parskip` documentation](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/parskip/parskip.pdf) is brief, just three pages, but here is a short summary of the package options:

* **`skip`**: specify `\parskip`, the vertical space between paragraphs;
* **`tocskip`**: specify a non-zero `\parskip` value for use in `\tableofcontents` and similar lists;
* **`indent`**: set the value of `\parindent`, the paragraph indentation;
* **`parfill`**: adjusts the value of `\parfillskip`, the glue added at the end of the last line in a paragraph.

By default, the `parskip` package sets `\parindent` to `0pt` and provides a non-zero `\parskip` value of `.5[\baselineskip](#baselineskip-tex-primitive) plus 2pt`.

#### parskip package examples

The following examples demonstrate some uses of the `parskip` package. Select the “Open in Overleaf” links to open and compile the examples using Overleaf.

**Minimal parskip package example**

The following minimal example loads the `parskip` package and typesets two paragraphs created using the [`blindtext` package](https://ctan.org/pkg/blindtext?lang=en). The example also typesets the default values of `\baselineskip`, `\parskip` and `\parindent`. The amount of space between the two paragraphs is determined by the value of `\parskip`:

```latex
\documentclass{article}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=14cm,textwidth=12cm]{geometry}
% Load blindtext package for dummy text
\usepackage{blindtext}
% Load the parskip package without options
\usepackage{parskip}
\begin{document}

\blindtext[1]\par %Use \par to force a new paragraph
\blindtext[1]

The value of \verb|\parindent| is \texttt{\the\parindent}. Here are the other values:

\begin{itemize}
\item The value of \verb|\baselineskip| is \texttt{\the\baselineskip}
\item The value of \verb|\parskip| is \texttt{\the\parskip}
\end{itemize}
\end{document}
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+use+of+the+parskip+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D14cm%2Ctextwidth%3D12cm%5D%7Bgeometry%7D%0A%25+Load+blindtext+package+for+dummy+text%0A%5Cusepackage%7Bblindtext%7D%0A%25+Load+the+parskip+package+without+options%0A%5Cusepackage%7Bparskip%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cblindtext%5B1%5D%5Cpar+%25Use+%5Cpar+to+force+a+new+paragraph%0A%5Cblindtext%5B1%5D%0A%0AThe+value+of+%5Cverb%7C%5Cparindent%7C+is+%5Ctexttt%7B%5Cthe%5Cparindent%7D.+Here+are+the+other+values%3A%0A%0A%5Cbegin%7Bitemize%7D%0A%5Citem+The+value+of+%5Cverb%7C%5Cbaselineskip%7C+is+%5Ctexttt%7B%5Cthe%5Cbaselineskip%7D%0A%5Citem+The+value+of+%5Cverb%7C%5Cparskip%7C+is+%5Ctexttt%7B%5Cthe%5Cparskip%7D%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Example use of the parskip LaTeX package](/files/UMd7lT5dRFTJgqWLtc4X)

Note that `\parskip` glue typically contains a stretchable [glue component](#a-few-notes-on-glue) because that helps LaTeX fit content onto the page and produce the best (optimal) page breaks.

**Using parskip package options**

The following example loads and configures the `parskip` package using the `skip` and `indent` options. It also typesets two paragraphs, via the [`blindtext` package](https://ctan.org/pkg/blindtext?lang=en), and typesets the values of `\baselineskip`, `\parskip` and `\parindent`.

```latex
\documentclass{article}
% Choose a conveniently small page size
\usepackage[paperheight=18cm,paperwidth=14cm,textwidth=12cm]{geometry}
% Load blindtext package for dummy text
\usepackage{blindtext}
% Load the parskip package with skip and indent options
\usepackage[skip=10pt plus1pt, indent=40pt]{parskip}
\begin{document}

\blindtext[1]\par % Use \par to force a new paragraph
\blindtext[1]

The value of \verb|\parindent| was set via the \texttt{indent} option, so it is now \texttt{\the\parindent}. The other values are:

\begin{itemize}
\item \verb|\baselineskip| is \texttt{\the\baselineskip}
\item \verb|\parskip| was set via the \texttt{skip} option, so its value is \texttt{\the\parskip}
\end{itemize}
\end{document}
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+use+of+the+parskip+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D18cm%2Cpaperwidth%3D14cm%2Ctextwidth%3D12cm%5D%7Bgeometry%7D%0A%25+Load+blindtext+package+for+dummy+text%0A%5Cusepackage%7Bblindtext%7D%0A%25+Load+the+parskip+package+with+skip+and+indent+options%0A%5Cusepackage%5Bskip%3D10pt+plus1pt%2C+indent%3D40pt%5D%7Bparskip%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cblindtext%5B1%5D%5Cpar+%25+Use+%5Cpar+to+force+a+new+paragraph%0A%5Cblindtext%5B1%5D%0A%0AThe+value+of+%5Cverb%7C%5Cparindent%7C+was+set+via+the+%5Ctexttt%7Bindent%7D+option%2C+so+it+is+now+%5Ctexttt%7B%5Cthe%5Cparindent%7D.+The+other+values+are%3A%0A%0A%5Cbegin%7Bitemize%7D%0A%5Citem+%5Cverb%7C%5Cbaselineskip%7C+is+%5Ctexttt%7B%5Cthe%5Cbaselineskip%7D%0A%5Citem+%5Cverb%7C%5Cparskip%7C+was+set+via+the+%5Ctexttt%7Bskip%7D+option%2C+so+its+value+is+%5Ctexttt%7B%5Cthe%5Cparskip%7D%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![A second example use of the parskip LaTeX package](/files/hbMogXYSY0TEySZ1Ow3p)

### The setspace package

The [`setspace` package](https://ctan.org/pkg/setspace?lang=en) provides commands and environments to change the spacing of your document’s lines of text. Here is a brief summary of the main commands and environments provided by `setspace`:

* the commands **`\singlespacing`**, **`\onehalfspacing`** and **`\doublespacing`** can be used in the document preamble, or within the document body to change spacing in part, or all, of your document;
* the **`\setstretch{*baselinestretch amount*}`** command sets a custom spacing (via changes to [`\baselinestretch`](#demonstrating-baselinestretch))—it can also be used in the document preamble;
* the environments **`singlespace`**, **`singlespace*`** **`onehalfspace`** and **`doublespace`** allow line spacing to be changed for selected parts of the document’s text;
* the **`\SetSinglespace{*value*}`** command uses `*value*` to adjust single-line spacing to accommodate line spacing of text typeset with fonts whose character shapes (“glyphs”) are relatively small, or large, for the given point size. See the section [*Brief notes on fonts and point size*](#brief-notes-on-fonts-and-point-size) for an illustration demonstrating the variation of font glyph size for a given point size;
* the **`spacing`** environment provides custom spacing and requires one argument: the [`\baselinestretch` value](#demonstrating-baselinestretch) to use; for example:

```latex
\begin{spacing}{2.5}
...
...
\end{spacing}
```

#### setspace package examples

The following examples demonstrate some uses of the `setspace` package: click the “Open in Overleaf” links to open and compile the examples using Overleaf.

**Using \doublespacing in the document preamble**

```latex
\documentclass{article}
% Choose a conveniently small page size
\usepackage[paperheight=18cm,paperwidth=14cm,textwidth=12cm]{geometry}
% Load blindtext package for dummy text
\usepackage{blindtext}
% Load the setspace package
\usepackage{setspace}
% Using \doublespacing in the preamble
% changes text to double line spacing
\doublespacing
\begin{document}
\blindtext[1]
\end{document}
```

&#x20;[Open this `setspace` example in Overleaf.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+use+of+the+doublespacing+command\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D18cm%2Cpaperwidth%3D14cm%2Ctextwidth%3D12cm%5D%7Bgeometry%7D%0A%25+Load+blindtext+package+for+dummy+text%0A%5Cusepackage%7Bblindtext%7D%0A%25+Load+the+setspace+package%0A%5Cusepackage%7Bsetspace%7D%0A%25+Using+%5Cdoublespacing+in+the+preamble+%0A%25+changes+text+to+double+line+spacing%0A%5Cdoublespacing%0A%5Cbegin%7Bdocument%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Example of the setspace \doublespacing command](/files/05SyLppIC7T20ECaUMwA)

**Using the spacing environment**

Because the following code typesets 3 pages it is preferable to view the output on Overleaf by selecting the “Open in Overleaf” link provided below.

```latex
\documentclass{article}
% Choose a conveniently small page size
\usepackage[paperheight=18cm,paperwidth=14cm,textwidth=12cm]{geometry}
% Load blindtext package for dummy text
\usepackage{blindtext}
% Load the setspace package
\usepackage{setspace}
% Using \doublespacing in the preamble
% changes text to double line spacing
\doublespacing
\begin{document}
\blindtext[1]

Now, apply a larger (custom) spacing by applying a \verb|\baselinestretch| value of 3:

\begin{verbatim}
\begin{spacing}{3}
\blindtext[1]
\end{spacing}
\end{verbatim}

\begin{spacing}{2.5}
\blindtext[1]
\end{spacing}
Now, revert to \verb|\singlespacing|\singlespacing\blindtext[1]
\end{document}
```

&#x20;[Open this `setspace` example in Overleaf.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+use+of+various+setspace+commands\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D18cm%2Cpaperwidth%3D14cm%2Ctextwidth%3D12cm%5D%7Bgeometry%7D%0A%25+Load+blindtext+package+for+dummy+text%0A%5Cusepackage%7Bblindtext%7D%0A%25+Load+the+setspace+package%0A%5Cusepackage%7Bsetspace%7D%0A%25+Using+%5Cdoublespacing+in+the+preamble+%0A%25+changes+text+to+double+line+spacing%0A%5Cdoublespacing%0A%5Cbegin%7Bdocument%7D%0A%5Cblindtext%5B1%5D%0A%0ANow%2C+apply+a+larger+%28custom%29+spacing+by+applying+a+%5Cverb%7C%5Cbaselinestretch%7C+value+of+3%3A%0A%0A%5Cbegin%7Bverbatim%7D%0A%5Cbegin%7Bspacing%7D%7B3%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bspacing%7D%0A%5Cend%7Bverbatim%7D%0A%0A%5Cbegin%7Bspacing%7D%7B2.5%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bspacing%7D%0ANow%2C+revert+to+%5Cverb%7C%5Csinglespacing%7C%5Csinglespacing%5Cblindtext%5B1%5D%0A%5Cend%7Bdocument%7D)

**Using the singlespace\* environment**

As noted in the article [*Quick note on line spacing*](https://texblog.org/2011/09/30/quick-note-on-line-spacing/), the `setspace` package provides starred (`singlespace*`) and non-starred versions of the `singlespace` environment. Comments in the `setspace` package code note that the `singlespace*` environment is designed to “... give improved vertical spacing around itemize and quote environments”.

The following example uses itemized lists contained in two `minipage` environments, placed side-by-side, to demonstrate the different spacing produced by the `singlespace` and `singlespace*` environments.

```latex
\doublespacing
\blindtext[1]

\begin{minipage}{.4\textwidth}
\begin{singlespace}
Here is a bulleted list\par (\texttt{singlespace} environment).
\begin{itemize}
\item One
\item Two
\item Three
\end{itemize}
\end{singlespace}%
The list has ended.
\end{minipage}\kern10pt%
\begin{minipage}{.4\textwidth}
\begin{singlespace*}
Here is a bulleted list\par (\texttt{singlespace*} environment).
\begin{itemize}
\item One
\item Two
\item Three
\end{itemize}
\end{singlespace*}
The list has ended.
\end{minipage}
```

&#x20;[Open this `setspace` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+the+starred+singlespace+environment\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bsetspace%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cdoublespacing+%0A%5Cblindtext%5B1%5D%0A%0A%5Cbegin%7Bminipage%7D%7B.4%5Ctextwidth%7D%0A%5Cbegin%7Bsinglespace%7D%0AHere+is+a+bulleted+list%5Cpar+%28%5Ctexttt%7Bsinglespace%7D+environment%29.%0A%5Cbegin%7Bitemize%7D%0A%5Citem+One%0A%5Citem+Two%0A%5Citem+Three%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bsinglespace%7D%25%0AThe+list+has+ended.%0A%5Cend%7Bminipage%7D%5Ckern10pt%25%0A%5Cbegin%7Bminipage%7D%7B.4%5Ctextwidth%7D%0A%5Cbegin%7Bsinglespace%2A%7D%0AHere+is+a+bulleted+list%5Cpar+%28%5Ctexttt%7Bsinglespace%2A%7D+environment%29.%0A%5Cbegin%7Bitemize%7D%0A%5Citem+One%0A%5Citem+Two%0A%5Citem+Three%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bsinglespace%2A%7D%0AThe+list+has+ended.%0A%5Cend%7Bminipage%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Example of the LaTeX singlespace\* environment](/files/0AzkLiidHrSj7w671JEJ)

**Using the \setstretch command**

`\setstretch{*value*}` sets the value of `\baselinestretch` to *value* and triggers an *immediate* change in `\baselineslip` caused by `\baselinestretch`. The following example uses `\setstretch{1.618}`—the strange value of 1.618 is [explained later in the article](#understanding-and-calculating-values-for-baselinestretch)...

```latex
% The strange figure of 1.618 is explained later in the article.
\setstretch{1.618}
We write \verb|\setstretch{1.618}| to cause an immediate change to the line spacing. If we wrote \verb|\renewcommand{\baselinestretch}{1.618}| the line spacing would not be modified until a font-changing command, such as \verb|\selectfont|, is used.

\blindtext[1]
```

&#x20;[Open this `setspace` example in Overleaf.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+use+of+the+setstretch+command\&snip=%5Cdocumentclass%5B11pt%5D%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D18cm%2Cpaperwidth%3D14cm%2Ctextwidth%3D12cm%5D%7Bgeometry%7D%0A%25+Load+blindtext+package+for+dummy+text%0A%5Cusepackage%7Bblindtext%7D%0A%25+Load+the+setspace+package%0A%5Cusepackage%7Bsetspace%7D%0A%5Cbegin%7Bdocument%7D%0A%25+The+strange+figure+of+1.618+is+explained+later+in+the+article.%0A%5Csetstretch%7B1.618%7D%0AWe+write+%5Cverb%7C%5Csetstretch%7B1.618%7D%7C+to+cause+an+immediate+change+to+the+line+spacing.+If+we+wrote+%5Cverb%7C%5Crenewcommand%7B%5Cbaselinestretch%7D%7B1.618%7D%7C+the+line+spacing+would+not+be+modified+until+a+font-changing+command%2C+such+as+%5Cverb%7C%5Cselectfont%7C%2C+is+used.%0A%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Example of the \setstretch command](/files/ZB4DXtxm0XSygp3AG3GX)

**Using the \SetSinglespace command**

The following project is compiled via LuaLaTeX and uses the `fontspec` package to access the TeX Gyre Pagella fonts. It compares two paragraphs of text typeset in TeX Gyre Pagella: the first paragraph uses the default single-line spacing and the second has a larger single-line spacing due to applying `\SetSinglespace{1.1}`. Some people may prefer the second, slightly “opened up”, paragraph, finding it improves reading comfort, but that is, of course, a matter of personal preference.

```latex
\section*{Computer Modern default single spacing}
Some regular text. \blindtext[1]
\setmainfont{TeX Gyre Pagella}
\section*{TeX Gyre Pagella default single line spacing}
Here is some regular text. \blindtext[1]
\section*{TeX Gyre Pagella adjusted single line spacing}
Note: we need to issue \verb|\singlespacing| after writing
\verb|\SetSinglespace{1.1}|\SetSinglespace{1.1}\singlespacing
\begin{singlespace*}
Here is some regular text. \blindtext[1]
\end{singlespace*}
```

&#x20;[Open this `setspace` example in Overleaf.](https://www.overleaf.com/docs?engine=lualatex\&snip_name=Example+use+of+the+SetSinglespace+command\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bfontspec%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cusepackage%7Bsetspace%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%2A%7BComputer+Modern+default+single+spacing%7D%0ASome+regular+text.+%5Cblindtext%5B1%5D%0A%5Csetmainfont%7BTeX+Gyre+Pagella%7D%0A%5Csection%2A%7BTeX+Gyre+Pagella+default+single+line+spacing%7D%0AHere+is+some+regular+text.+%5Cblindtext%5B1%5D%0A%5Csection%2A%7BTeX+Gyre+Pagella+adjusted+single+line+spacing%7D%0ANote%3A+we+need+to+issue+%5Cverb%7C%5Csinglespacing%7C+after+writing++%0A%5Cverb%7C%5CSetSinglespace%7B1.1%7D%7C%5CSetSinglespace%7B1.1%7D%5Csinglespacing%0A%5Cbegin%7Bsinglespace%2A%7D+%0AHere+is+some+regular+text.+%5Cblindtext%5B1%5D%0A%5Cend%7Bsinglespace%2A%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Demonstration of the LaTeX \SetSinglespace command](/files/D3AsOwJz8BHjOA9KdfRE)

In the next section we review the commands `\baselinestretch` and `\linespread`.

#### Understanding \baselinestretch and \linespread

Part of LaTeX’s design for handling line spacing and font changes (font size, font family, font encoding etc) makes use of two commands that you might encounter:

* **`\baselinestretch`**: this command stores a scaling factor used to multiply (scale) the current value of [`\baselineskip`](#baselineskip-tex-primitive). That scaling is typically applied the *next time* a font-selection command is used—such as `\selectfont`. To change the value stored by `\baselinestretch` you should write `\renewcommand{\baselinestretch}{*scale*}`
  * **Note**: If you write `\renewcommand{\baselinestretch}{*scale*}` in the body of the document, the new value of `\baselinestretch` [will not take immediate effect](https://tex.stackexchange.com/questions/241120/why-does-changing-baselinestretch-not-change-line-spacing): the new `*scale*` factor is stored for future use. To immediately use/apply the new`*scale*` value, write `\selectfont` as demonstrated in the [code fragment below](#demonstrating-baselinestretch).
* **`\linespread{*scale*}`**: can be used to change [`\baselineskip`](#baselineskip-tex-primitive) without affecting the current font size. This command sets `\baselinestretch` to `*scale*` which subsequently changes `\baselineskip` to `*scale* × [\baselineskip](#baselineskip-tex-primitive)`. However, that scaling also does not take place immediately unless the `\linespread` command is used in the document preamble. If `\linespread` used in the document body, it takes effect after the next font sizing/selection command is used.

Based on the above, either:

* `\renewcommand{\baselinestretch}{*scale*}\selectfont` or,
* `\linespread{*scale*}\selectfont`

could be used to change line spacing, and both will work across changes to the font size, as demonstrated in the example below. So, which one should you use? Refer to [this short discussion on tex.stackexchange](https://tex.stackexchange.com/a/241121).

**Demonstrating \linespread**

The following example uses `\linespread{2.5}` in the document preamble, which changes line spacing without requiring additional font-selection commands:

```latex
\documentclass{article}
% Choose a conveniently small page size
\usepackage[paperheight=18cm,paperwidth=14cm,textwidth=12cm]{geometry}
% Load blindtext package for dummy text
\usepackage{blindtext}
% Using \linespread in the preamble changes
% line spacing without requiring additional
% font-selection commands, such as \selectfont
\linespread{2.5}
\begin{document}
\blindtext[1] % The lines are affected by \linespread{2.5}
\end{document}
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+use+of+the+linestretch+command\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D18cm%2Cpaperwidth%3D14cm%2Ctextwidth%3D12cm%5D%7Bgeometry%7D%0A%25+Load+blindtext+package+for+dummy+text%0A%5Cusepackage%7Bblindtext%7D%0A%25+Using+%5Clinespread+in+the+preamble+changes+%0A%25+line+spacing+without+requiring+additional%0A%25+font-selection+commands%2C+such+as+%5Cselectfont%0A%5Clinespread%7B2.5%7D+%0A%5Cbegin%7Bdocument%7D%0A%5Cblindtext%5B1%5D+%25+The+lines+are+affected+by+%5Clinespread%7B2.5%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Using the linespread command](/files/zlD3E4BYeYvsnouILmTm)

Using `\linespread{2.5}` in the document body (after `\begin{document}`) *would* require font-selection commands to trigger the change in line spacing. Open the following code on Overleaf and compare the output with the previous example:

```latex
Because the following \verb|\linespread| command is used in the document body, a font-selection command is required to change the line spacing. Un-comment \verb|\selectfont| to see the difference:

\linespread{2.5}%\selectfont

% Without \selectfont the following paragraph lines are
% unaffected affected by \linespread{2.5}:
\blindtext[1]
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Second+example+using+the+linestretch+command\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D18cm%2Cpaperwidth%3D14cm%2Ctextwidth%3D12cm%5D%7Bgeometry%7D%0A%25+Load+blindtext+package+for+dummy+text%0A%5Cusepackage%7Bblindtext%7D%0A%5Cbegin%7Bdocument%7D%0ABecause+the+following+%5Cverb%7C%5Clinespread%7C+command+is+used+in+the+document+body%2C+a+font-selection+command+is+required+to+change+the+line+spacing.+Un-comment+%5Cverb%7C%5Cselectfont%7C+to+see+the+difference%3A%0A%0A%5Clinespread%7B2.5%7D%25%5Cselectfont%0A+%0A%25+Without+%5Cselectfont+the+following+paragraph+lines+are+%0A%25+unaffected+affected+by+%5Clinespread%7B2.5%7D%3A+%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![using LaTeX \linespread command in the document](/files/SL8T2Ee1vvpcbnAdq8XS)

**Demonstrating \baselinestretch**

The following example demonstrates `\baselinestretch` and `\selectfont` to show the corresponding effect(s) on [`\baselineskip`](#baselineskip-tex-primitive):

```latex
The default value of \verb|\baselineskip|=\the\baselineskip. Now update \verb|\baselinestretch|\renewcommand\baselinestretch{2.5}. However, although we have executed

\vspace{5pt}
\verb|\renewcommand\baselinestretch{2.5}|
\vspace{5pt}

\noindent it \textit{has not} (yet) had any effect: the new value of \verb|\baselinestretch| is stored, but not actioned. We can issue a \verb|\selectfont| command to make the change take effect; but, for now, the value of \verb|\baselineskip| is still \the\baselineskip{} (unchanged).

If we now execute \verb|\selectfont| the change to \verb|\baselinestretch|, setting it to 2.5, will now take effect---\selectfont even though we are in the middle of a paragraph. Now, the value of \verb|\baselineskip| is \the\baselineskip{} (= \(2.5 \times 12=30\mathrm{pt}\)).

What happens if we change the font size to 14pt and \verb|\baselineskip| to 16pt using the commands \verb|\fontsize{14}{16}\selectfont|?

\fontsize{14}{16}\selectfont Now, \verb|\baselineskip| is \textit{not} 16pt but \the\baselineskip{} because the value of  \verb|\baselinestretch| (2.5) has been preserved and applied, giving \verb|\baselineskip| = \(2.5 \times 16=40\mathrm{pt}\).

\section{\texttt{\bfseries\string\linespread}}
The \verb|\linespread| command can be used to modify \verb|\baselineskip| without changing the font size.
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+baselinestretch\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D18cm%2Cpaperwidth%3D16cm%2Ctextwidth%3D14cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Bsetspace%7D%0A%5Cbegin%7Bdocument%7D%0AThe+default+value+of+%5Cverb%7C%5Cbaselineskip%7C%3D%5Cthe%5Cbaselineskip.+Now+update+%5Cverb%7C%5Cbaselinestretch%7C%5Crenewcommand%5Cbaselinestretch%7B2.5%7D.+However%2C+although+we+have+executed%0A%0A%5Cvspace%7B5pt%7D%0A%5Cverb%7C%5Crenewcommand%5Cbaselinestretch%7B2.5%7D%7C+%0A%5Cvspace%7B5pt%7D%0A%0A%5Cnoindent+it+%5Ctextit%7Bhas+not%7D+%28yet%29+had+any+effect%3A+the+new+value+of+%5Cverb%7C%5Cbaselinestretch%7C+is+stored%2C+but+not+actioned.+We+can+issue+a+%5Cverb%7C%5Cselectfont%7C+command+to+make+the+change+take+effect%3B+but%2C+for+now%2C+the+value+of+%5Cverb%7C%5Cbaselineskip%7C+is+still+%5Cthe%5Cbaselineskip%7B%7D+%28unchanged%29.+%0A%0AIf+we+now+execute+%5Cverb%7C%5Cselectfont%7C+the+change+to+%5Cverb%7C%5Cbaselinestretch%7C%2C+setting+it+to+2.5%2C+will+now+take+effect---%5Cselectfont+even+though+we+are+in+the+middle+of+a+paragraph.+Now%2C+the+value+of+%5Cverb%7C%5Cbaselineskip%7C+is+%5Cthe%5Cbaselineskip%7B%7D+%28%3D+%5C%282.5+%5Ctimes+12%3D30%5Cmathrm%7Bpt%7D%5C%29%29.%0A%0AWhat+happens+if+we+change+the+font+size+to+14pt+and+%5Cverb%7C%5Cbaselineskip%7C+to+16pt+using+the+commands+%5Cverb%7C%5Cfontsize%7B14%7D%7B16%7D%5Cselectfont%7C%3F+%0A%0A%5Cfontsize%7B14%7D%7B16%7D%5Cselectfont+Now%2C+%5Cverb%7C%5Cbaselineskip%7C+is+%5Ctextit%7Bnot%7D+16pt+but+%5Cthe%5Cbaselineskip%7B%7D+because+the+value+of++%5Cverb%7C%5Cbaselinestretch%7C+%282.5%29+has+been+preserved+and+applied%2C+giving+%5Cverb%7C%5Cbaselineskip%7C+%3D+%5C%282.5+%5Ctimes+16%3D40%5Cmathrm%7Bpt%7D%5C%29.%0A%0A%5Csection%7B%5Ctexttt%7B%5Cbfseries%5Cstring%5Clinespread%7D%7D%0AThe+%5Cverb%7C%5Clinespread%7C+command+can+be+used+to+modify+%5Cverb%7C%5Cbaselineskip%7C+without+changing+the+font+size.%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Demonstrating baselinestretch](/files/dNEAJFNUY67dRHpMgRrR)

#### How is “line spacing” defined and changed in the setspace package?

The *precise* definition, and *measurement* of, “line spacing” is open to interpretation, which can result in various implementations within software systems/applications. Clearly, the `setspace` package has to assume a working definition of line spacing so that it can provide support for typesetting “single-” and “double-spaced” lines, or any other multiple of line spacing. But which variables are modified by `setspace` to produce lines with differing levels of white space between them?

Fortunately, [discussions on tex.stackexchange](https://tex.stackexchange.com/a/30106) and [comments in the package code](https://tex.stackexchange.com/a/632830) clarify how `setspace` implements lines spacing: it sets the value of `\baselineskip` using a multiple of the font’s point size.

**Brief notes on fonts and point size**

Using fonts at a particular point size means applying a *scaling factor* to the character shapes (glyphs) in those fonts; once scaled according to the point size, the visible size of the character is a function of the font’s design (typeface). Point size has no universal, hard-and-fast, relationship to the actual display size of character shapes within fonts.

The following image shows lowercase letters “abc” styled using 4 different fonts and all *displayed at the same point size*. Note how the “size” of these lowercase letters varies according to the font’s design (typeface) even though they are all typeset at the *same* point size:

![Various fonts at the same pointsize](/files/YULr4AuHlaIAfg1tfHAj)

#### Single line space in the setspace package

We can use [discussions on tex.stackexchange](https://tex.stackexchange.com/a/30106) as a basis for some further explanations.

A basic document using the `article` class has a default text font size of 10pt with a `\baselineskip` of 12pt. With the option \[11pt] or \[12pt] the article class uses a larger text size and correspondingly larger value for `\baselineskip` as shown in the following table:

| option            | font size                   | $$\texttt{\baselineskip}$$ | $$\displaystyle\frac{\texttt{\baselineskip}}{\text{font size}}$$ |
| ----------------- | --------------------------- | -------------------------- | ---------------------------------------------------------------- |
| \[10pt] (default) | 10pt                        | 12pt                       | 1.2                                                              |
| \[11pt]           | 10.95pt$${}^{\textbf{\*}}$$ | 13.6pt                     | 1.24                                                             |
| \[12pt]           | 12pt                        | 14.5                       | 1.21                                                             |

$${}^{\textbf{\*}}$$The reason for the anomalous value of `10.95pt`, and not exactly `11pt`, is nicely explained in this [reddit post](https://www.reddit.com/r/LaTeX/comments/ihle9h/why_does_latex_use_1095pt_text_when_the_11pt/).

As shown in the table, for each combination of text point size, and the corresponding default (i.e., single-line spacing) value of `\baselineskip`, the ratio

$$\frac{\texttt{\baselineskip}}{\text{font size}}$$

is close to 1.2. That ratio value designates single-line spacing and provides the basis for line-spacing calculations used by the `setspace` package.

**Understanding and calculating values for \baselinestretch**

To achieve a particular line-spacing multiple such as 1.5, 2, 3 etc., the `\baselinestretch` command has to be set to seemingly [“strange” values](https://tex.stackexchange.com/a/30106); for example by [using the `\linespread` command](https://texblog.org/2011/09/30/quick-note-on-line-spacing/). In this section we’ll take a closer look at `\baselinestretch` to see how those “strange” values arise.

Let’s choose a document with default font size of $$f$$ and default `\baselineskip` of $$\text{dbls}\_1$$, where the subscript $${}\_1$$ implies default `\baselineskip` value for single-line spacing at font size $$f$$.

We’ll ***define*** single-line spacing as the following ratio which we’ll refer to as $$\alpha\_f$$:

$$\frac{\text{dbls}\_1}{f}=\alpha\_f$$

For a given font size $$f$$, let’s also *define* the following line spacing values:

* a 1.5 multiple of line spacing is *defined* as

$$\frac{\text{dbls}\_{1.5}}{f}=1.5$$

* a 2.0 multiple of line spacing is *defined* as

$$\frac{\text{dbls}\_{2.0}}{f}=2.0$$

* a multiple, $$m$$, of line spacing is *defined* as

$$\frac{\text{dbls}\_{m}}{f}=m$$

Using our single-line spacing, defined by the ratio $$\alpha\_f$$, we can write the following “pseudo code” to work out a `\baselinestretch` value corresponding to any line-space multiple $$m$$:

$$\begin{align\*} \texttt{multi spacing } (m) &= \text{a constant } (\lambda) \times \texttt{single spacing}\ \frac{\text{dbls}\_{m}}{f}&=\lambda \times \alpha\_f\ m&=\lambda\alpha\_f\ \lambda&=\frac{m}{\alpha\_f}\kern5pt(\text{refer to }\lambda\text{ as }\texttt{\baselinestretch})\ \implies \texttt{\baselinestretch}&=\frac{m}{\alpha\_f} \end{align\*}$$

Let’s use `11pt` text (actually `10.95pt`) and the default `\baselineskip` value of `13.6pt` to calculate `\baselinestretch` for *double* line spacing:

$$\begin{align\*} m&=2.0\ \texttt{\baselinestretch}&=\frac{2.0}{\alpha\_f}\ &=\frac{2.0}{\frac{\text{dbls}\_1}{f}}\ &=\frac{2.0}{\frac{13.6}{11}}\ &=2.0 \times \frac{11}{13.6}\ &=1.618\ \end{align\*}$$

The following code fragment is used in the `setspace` package to achieve `\doublespacing` when the font size is 11pt. Note how the value of `1.618`, as calculated above, is stored in the command `\baselinestretch`:

```latex
\newcommand{\doublespacing}{%
  \setstretch {1.667}%  default
  \ifcase \@ptsize \relax % 10pt
    \setstretch {1.667}%
  \or % 11pt
    \setstretch {1.618}%
  \or % 12pt
    \setstretch {1.655}%
  \fi
}
```

Using an `article` document class with the 11pt font option, the following example compares `\doublespacing` with a `spacing` environment using our calculated value of `1.618` for `\baselinestretch`. Not surprisingly, the `\baselineskip` values are identical (`22.00475pt`):

```latex
\begingroup
\doublespacing
\verb|\baselineskip|=\texttt{\the\baselineskip} (via \verb|\doublespacing)|

\blindtext[1]

\endgroup

\begin{spacing}{1.618}
\verb|\baselineskip|=\texttt{\the\baselineskip} (via \verb|\begin{spacing}{1.618})|

\blindtext[1]
\end{spacing}
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+baselinestretch+calculations\&snip=%5Cdocumentclass%5B11pt%5D%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D25cm%2Cpaperwidth%3D16cm%2Ctextwidth%3D14cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Bsetspace%7D%0A%5Cusepackage%7Bblindtext%7D+%25+For+dummy+text.%0A%5Cbegin%7Bdocument%7D%0A%5Cbegingroup%0A%5Cdoublespacing%0A%5Cverb%7C%5Cbaselineskip%7C%3D%5Ctexttt%7B%5Cthe%5Cbaselineskip%7D+%28via+%5Cverb%7C%5Cdoublespacing%29%7C%0A%0A%5Cblindtext%5B1%5D%0A%0A%5Cendgroup%0A%0A%5Cbegin%7Bspacing%7D%7B1.618%7D%0A%5Cverb%7C%5Cbaselineskip%7C%3D%5Ctexttt%7B%5Cthe%5Cbaselineskip%7D+%28via+%5Cverb%7C%5Cbegin%7Bspacing%7D%7B1.618%7D%29%7C%0A%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bspacing%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![demonstration of \baselinestretch](/files/iiS8Y3bLkirKvQxvwAAv)

Similar calculations of `\baselinestretch` values apply to other font sizes and line spacing combinations, as listed in the following tables:

![setspace parameters](/files/21Rzz36Wu3l2X0lDZxzX)

## Using TeX/LaTeX parameter commands

The following sections explore a number of commands related to paragraph spacing/formatting: some of those commands are *built into* TeX typesetting engines, others are TeX/LaTeX macros. Commands built into TeX engines are known as *primitives*, meaning they are *fundamental* and *irreducible* because, unlike macros, primitives are not constructed from sequences of other commands.

In particular, we’ll consider a number of primitive *parameter commands* supported by all TeX engines, including pdfTeX, XeTeX and LuaTeX. Parameter commands, whether paragraph-related or not, are used to *get the current value* of the corresponding parameter, or *set that parameter to a new value*. For example, the `\parskip` command, a primitive, determines the value of a parameter which controls the amount of white space inserted between two typeset paragraphs.

To *get* (here, to typeset) the current value of `\parskip` you would write:

```latex
\the\parskip
```

To *set* the current value of `\parskip` to `1pt plus2pt` (a flexible glue) you could write something like this:

```latex
\setlength{\parskip}{1pt plus2pt}
```

We also discuss some useful TeX/LaTeX *macros*, higher-level commands written and constructed using a sequence of constituent commands.

### Commands used for paragraph spacing

The following commands (primitives and macros) can be used to affect paragraph spacing. Some are explored in more detail which can be accessed by following the link from the command name.

#### Primitive commands

* [`**\parindent**`](#parindent-tex-primitive): the amount of indentation (white space) added to the first line of a paragraph.
* [`**\parskip**`](#parskip-tex-primitive): the amount of flexible white space (“glue”) placed between paragraphs.
* [`**\rightskip**`](#leftskip-and-rightskip-tex-primitives): flexible spacing (glue) inserted to the right of each line in a paragraph.
* [`**\leftskip**`](#leftskip-and-rightskip-tex-primitives): flexible spacing (glue) inserted to the left of each line in a paragraph.
* [`**\baselineskip**`](#baselineskip-tex-primitive): the value of this parameter serves two roles:
  * it sets the desired distance between the baselines of text in a paragraph;
  * it is used to calculate the (variable) amount of space (glue) added between lines in order to achieve the desired baseline-to-baseline distance ([see later in the article](#how-the-space-glue-between-paragraph-lines-is-calculated)).
* [`**\lineskiplimit**`](#lineskip-and-lineskiplimit-tex-primitives): a parameter whose value defines the minimum acceptable distance between two adjacent lines of a paragraph.
* [`**\lineskip**`](#lineskip-and-lineskiplimit-tex-primitives): the amount of space (glue) inserted between two lines in a paragraph if the calculated `\baselineskip` glue would result in lines being too close together.
* `**\parfillskip**`: very flexible glue added at the end of the last line in a paragraph in order to “fill it” with white space; for a visual example, refer to the illustration in the section [*Visualizing other types of paragraph glue*](#visualizing-other-types-of-paragraph-glue).

#### Macro commands

The following TeX/LaTeX macro commands are often used to modify paragraph spacing:

* [`**\offinterlineskip**` and `**\nointerlineskip**`](#offinterlineskipandnointerlineskip): commands which can be used to switch off calculation and insertion of `\baselineskip` glue;
* [`**\baselinestretch**`](#understanding-and-calculating-values-for-baselinestretch): a command which stores a numeric factor used to calculate the value of `\baselineskip` when a font is selected. It has a default value of 1;
* [`**\linespread**`](#demonstrating-linespread): this command can be used to change the current value of `\baselinestretch`.

### Flexible spacing (glue)

TeX engines achieve spacing effects, including within or between paragraphs, through the use of a flexible white space called *glue* which can be stretched or shrunk according to the amount of space required. If you want to learn about TeX’s concept of glue, more details can be found in the following Overleaf articles:

* [Exploring underfull or overfull boxes and badness calculations](https://www.overleaf.com/latex/examples/exploring-underfull-or-overfull-boxes-and-badness-calculations/wpfsjnbkrfhv)
* [How TeX calculates glue settings in an \hbox](/latex/in-depth-articles/24-how-tex-calculates-glue-settings-in-an-hbox.md)
* [Understanding underfull and overfull box warnings](/latex/knowledge-base/138-understanding-underfull-and-overfull-box-warnings.md).

## The fundamentals: parameter commands and examples

In this section we explain a number of paragraph-related parameter commands and provide examples of their use.

### \parindent (TeX primitive)

This parameter command sets the amount of indentation (white space) added to the first line of a paragraph. It can be changed by using LaTeX’s `\setlength` command; for example, to indent paragraphs by `15pt` set `\parindent` to `15pt` by writing:

```latex
\setlength{\parindent}{15pt}
```

Note that:

* you can change `\parindent` within a group, ensuring its effect is localized to paragraphs in that group;
* `\parindent` can be negative, producing an “outdent” rather than an indent;
* by default LaTeX does not indent the first paragraph following a document section heading (`\section{...}` etc).

The following example demonstrates the use of `\parindent`.

```latex
\documentclass{article}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=8cm]{geometry}
% Create a command to hold a paragraph of text
\newcommand{\testpar}{\texttt{\string\parindent=\the\parindent\ }When \TeX{} typesets a paragraph it treats each individual character as a 2D ``box'' with a specific width, height and depth.\par}
\begin{document}

% Set \parskip to put 10pt between paragraphs
\setlength{\parskip}{10pt}

% Set the value of \parindent to 0pt
\setlength{\parindent}{0pt}
\testpar

% Set the value of \parindent to 10pt
\setlength{\parindent}{10pt}
\testpar

% Set \parindent in a group
{\setlength{\parindent}{50pt}\testpar}

% Now \parindent is again 10pt
\testpar

% Yes, you can have a negative \parindent
\setlength{\parindent}{-20pt}
\testpar
\end{document}
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Changing+paragraph+indentation\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D8cm%5D%7Bgeometry%7D%0A%25+Create+a+command+to+hold+a+paragraph+of+text%0A%5Cnewcommand%7B%5Ctestpar%7D%7B%5Ctexttt%7B%5Cstring%5Cparindent%3D%5Cthe%5Cparindent%5C+%7DWhen+%5CTeX%7B%7D+typesets+a+paragraph+it+treats+each+individual+character+as+a+2D+%60%60box%27%27+with+a+specific+width%2C+height+and+depth.%5Cpar%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%25+Set+%5Cparskip+to+put+10pt+between+paragraphs%0A%5Csetlength%7B%5Cparskip%7D%7B10pt%7D%0A%0A%25+Set+the+value+of+%5Cparindent+to+0pt%0A%5Csetlength%7B%5Cparindent%7D%7B0pt%7D%0A%5Ctestpar%0A%0A%25+Set+the+value+of+%5Cparindent+to+10pt%0A%5Csetlength%7B%5Cparindent%7D%7B10pt%7D%0A%5Ctestpar%0A%0A%25+Set+%5Cparindent+in+a+group%0A%7B%5Csetlength%7B%5Cparindent%7D%7B50pt%7D%5Ctestpar%7D%0A%0A%25+Now+%5Cparindent+is+again+10pt%0A%5Ctestpar%0A%0A%25+Yes%2C+you+can+have+a+negative+%5Cparindent%0A%5Csetlength%7B%5Cparindent%7D%7B-20pt%7D%0A%5Ctestpar%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Using various paragraph indent values in LaTeX](/files/3jqhm4NRWYtWCTukaqq2)

### \parskip (TeX primitive)

The legibility of text can be enhanced by separating paragraphs with an amount of white space that will vary according to some design aesthetic. TeX/LaTeX allow users to control that inter-paragraph spacing via the `\parskip` parameter command.

* **Advice from the `parskip` package**: The [parskip package](https://ctan.org/pkg/parskip) advises that directly modifying `\parskip` can “result in vertical spaces in unexpected places” (within a LaTeX document). The `parskip` package attempts to fix spacing issues that might arise from changes to the value of `\parskip`—such as within table of contents and list environments. See also the [`parskip` package section of this article](#the-parskip-package).

To manually set the current value of `\parskip` use LaTeX’s `\setlength` command; for example, to separate paragraphs by 3pt you can write:

```latex
\setlength{\parskip}{3pt}
```

The following example demonstrates the use of `\parskip`:

```latex
\documentclass{article}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=8cm]{geometry}
% Create a command to hold a paragraph of text
\newcommand{\testpar}{\noindent The current value of \texttt{\string\parskip} is \texttt{\the\parskip}. When \TeX{} typesets a paragraph it treats each individual character as a 2D~``box'' with a specific width, height and depth.\par}
\begin{document}
\testpar
% Set \parskip to 5pt
\setlength{\parskip}{5pt}\testpar
% Set parskip to 10pt
\setlength{\parskip}{10pt}\testpar
% Set \parskip to 25pt (but in a group)
{\setlength{\parskip}{25pt}\testpar}
% Group ends, now \parskip is again 10pt
\testpar
% Yes, you can have a negative \parskip
\setlength{\parskip}{-20pt}\testpar
\end{document}
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Changing+parskip+settings\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D8cm%5D%7Bgeometry%7D%0A%25+Create+a+command+to+hold+a+paragraph+of+text%0A%5Cnewcommand%7B%5Ctestpar%7D%7B%5Cnoindent+The+current+value+of+%5Ctexttt%7B%5Cstring%5Cparskip%7D+is+%5Ctexttt%7B%5Cthe%5Cparskip%7D.+When+%5CTeX%7B%7D+typesets+a+paragraph+it+treats+each+individual+character+as+a+2D%7E%60%60box%27%27+with+a+specific+width%2C+height+and+depth.%5Cpar%7D%0A%5Cbegin%7Bdocument%7D%0A%5Ctestpar%0A%25+Set+%5Cparskip+to+5pt+%0A%5Csetlength%7B%5Cparskip%7D%7B5pt%7D%5Ctestpar%0A%25+Set+parskip+to+10pt%0A%5Csetlength%7B%5Cparskip%7D%7B10pt%7D%5Ctestpar%0A%25+Set+%5Cparskip+to+25pt+%28but+in+a+group%29%0A%7B%5Csetlength%7B%5Cparskip%7D%7B25pt%7D%5Ctestpar%7D%0A%25+Group+ends%2C+now+%5Cparskip+is+again+10pt%0A%5Ctestpar%0A%25+Yes%2C+you+can+have+a+negative+%5Cparskip%0A%5Csetlength%7B%5Cparskip%7D%7B-20pt%7D%5Ctestpar%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Demonstrating the use of \parskip in LaTeX](/files/M7ABclidh9LJ078LLXgo)

#### Flexible \parskip

Traditionally, `\parskip` is not a *fixed* value, which would result in the same amount of space between all paragraphs. Instead, `\parskip` is usually defined as a “flexible space” (called glue) which enables TeX to stretch or shrink the space between paragraphs, helping to fit content on the page and find a “good” place for a page break.

To make `\parskip` flexible you would write it in the form of a glue specification:

`\setlength{\parskip}{*fixed amount* **plus** *amount to stretch* **minus** *amount to shrink*}`

where `**plus**` and `**minus**` are *keywords* used by TeX/LaTeX to identify the *amount to stretch* or *amount to shrink* contained in a glue specification. The Overleaf article [*Exploring underfull or overfull boxes and badness calculations*](https://www.overleaf.com/latex/examples/exploring-underfull-or-overfull-boxes-and-badness-calculations/wpfsjnbkrfhv) contains a more in-depth discussion of glue.

For example, to enable `\parskip` to vary between `3 + 1 = 4pt` and `3 — 1 = 2pt` you could write

```latex
\setlength{\parskip}{3pt plus1pt minus1pt}
```

### \leftskip and \rightskip (TeX primitives)

TeX engines provide two parameter commands which add space (glue) to the left and right of each line in the typeset paragraph. As their names suggest:

* `\leftskip` inserts space (glue) to the left of each line in a paragraph;
* `\rightskip` inserts space (glue) to right left of each line in a paragraph.

The following examples use `\leftskip` and `\rightskip` to directly modify paragraph alignment; however... changes to text alignment are usually best achieved via suitable LaTeX environments or packages—for example, see the [Overleaf article on text alignment](/latex/formatting/06-text-alignment.md). Although we demonstrate the behaviour of some low-level (primitive) parameter commands provided by TeX engines, it is generally advisable to use appropriate LaTeX packages wherever possible.

#### Making \leftskip fixed and \rightskip flexible

The following example produces two paragraphs: the first uses LaTeX’s default values for `\leftskip` and `\rightskip` and the second paragraph is typeset using the following settings:

```latex
\leftskip 10pt
\rightskip 0pt plus 1 fill
```

Open the following Overleaf project to see the output:

```latex
\documentclass{article}
\title{Second leftskip and rightskip example}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=8cm]{geometry}
% Set the value of some paragraph-related parameters
\setlength{\lineskip}{3.5pt}
\setlength{\lineskiplimit}{2pt}
\setlength{\parindent}{20pt}
\setlength{\baselineskip}{12pt}

\begin{document}
\input text.tex % A generated TeX file which defines the macros
% \mytextA and \mytextB, each containing the text for a paragraph.
% Typeset a paragraph with default values of \leftskip and \rightskip

\mytextB

% Set \leftskip and \rightskip to new values
\leftskip 10pt
\rightskip 0pt plus 1fill
\vspace{8pt}

% Now re-typeset the same paragraph
\mytextB

\end{document}
```

&#x20;Open this example as an Overleaf LaTeX project

This example generates the following output:

![Setting \leftskip glue in LaTeX](/files/55KL7188SZAGb9TBh5AB)

The following graphic is an annotated version of the second paragraph produced by the example above. It is designed to highlight and show the amount of `\leftskip` and `\rightskip` glues inserted in the paragraph lines, together with the `\parindent` space for the first line:

![Setting \leftskip glue in LaTeX](/files/V6c80UdF8hDcqyanIJOu)

Note that `\leftskip` glue has a fixed size (10pt) but `\rightskip` glue has stretched to provide any amount of white space required to fill up the right-hand side of each line. This “flexibility” is due to the specification of `\rightskip` which contains `plus 1 fill`—providing an “infinitely stretchable” form of glue.

#### Making \rightskip fixed and \leftskip flexible

The following example produces two paragraphs: the first uses LaTeX’s default values for `\leftskip` and `\rightskip` and the second paragraph is typeset using the following settings:

```latex
\leftskip 0pt plus 1 fill
\rightskip 10pt
```

Open the following Overleaf project to see the output:

```latex
\documentclass{article}
\title{leftskip and rightskip examples}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=8cm]{geometry}
% Set the value of some paragraph-related parameters
\setlength{\lineskip}{3.5pt}
\setlength{\lineskiplimit}{2pt}
\setlength{\parindent}{20pt}
\setlength{\baselineskip}{12pt}

\begin{document}
\input text.tex % A generated TeX file which defines the macros
% \mytextA and \mytextB, each containing the text for a paragraph.
% Typeset a paragraph with default values of \leftskip and \rightskip

\mytextB

% Set \leftskip and \rightskip to new values
\rightskip 10pt
\leftskip 0pt plus 1fill
\vspace{8pt}

% Now re-typeset the same paragraph
\mytextB

\end{document}
```

&#x20;Open this example as an Overleaf LaTeX project

This example generates the following output:

![Setting \rightskip glue in LaTeX](/files/5zrwOGU9MEIrLkNCKB18)

The following graphic is an annotated version of the second paragraph produced by example above. It is designed to highlight and show the amount of `\leftskip` and `\rightskip` glues inserted in the paragraph lines, together with the `\parindent` space for the first line:

![Setting \rightskip glue in LaTeX](/files/PcGLVAhHHKAI8ein8UWn)

Note that `\rightskip` glue has a fixed size (10pt) but `\leftskip` glue has stretched to provide any amount of white space required to fill up the left-hand side of each line. This “flexibility” is due to the specification of `\leftskip` which contains `plus 1 fill`—providing an “infinitely stretchable” form of glue.

#### Setting \leftskip and \rightskip to flexible values

The following example produces two paragraphs: the first uses LaTeX’s default values for `\leftskip` and `\rightskip` and the second uses the following, flexible, glue settings:

```latex
\leftskip 0pt plus 1fill
\rightskip 0pt plus 1fill
```

These settings result in paragraph lines being centered:

```latex
\documentclass{article}
\title{leftskip and rightskip examples}
% Choose a conveniently small page size
\usepackage[paperheight==16cm,paperwidth==12cm,textwidth=8cm]{geometry}
% Set the value of some paragraph-related parameters
\setlength{\lineskip}{3.5pt}
\setlength{\lineskiplimit}{2pt}
\setlength{\parindent}{20pt}
\setlength{\baselineskip}{12pt}

\begin{document}
\input text.tex % A generated TeX file which defines the macros
% \mytextA and \mytextB which define text for two paragraphs
% Typeset a paragraph with default values of \leftskip and \rightskip

\mytextB

% Set \leftskip and \rightskip to "extremely flexible" glue settings
\leftskip 0pt plus 1fill
\rightskip 0pt plus 1fill
\vspace{20pt}

% Now re-typeset the same paragraph
\mytextB

\end{document}
```

&#x20;Open this example as an Overleaf LaTeX project

This example generates the following output:

![Example showing \leftskip and \rightskip](/files/3CcjH4UU1x9Xx8anoOyb)

The following graphic is an annotated version of the second paragraph produced by example above. It is designed to highlight and show the amount of `\leftskip` and `\rightskip` glues inserted in the paragraph lines, together with the `\parindent` space for the first line:

![Example showing \leftskip and \rightskip](/files/FtCDXJSXcWETkYTknz60)

Note that both `\leftskip` and `\rightskip` are specified as `0pt plus 1fill` making them equally “infinitely flexible”; consequently, they stretch by the same amount which results in typeset lines being centred.

#### Setting \leftskip and \rightskip in a group

The following example shows how to make temporary changes to `\leftskip` and `\rightskip` by enclosing them inside a group. In our example the group is created by `\begingroup`... `\endgroup`, as shown in the following code fragment:

```latex
\begingroup
\leftskip 0pt plus 1fill
\rightskip 0pt plus 1fill
\mytextB
\endgroup
```

The first paragraph is typeset using “extremely flexible” glue for `\leftskip` and `\rightskip`:

```latex
\leftskip 0pt plus 1fill
\rightskip 0pt plus 1fill
```

but the second paragraph uses LaTeX’s default values:

```latex
\documentclass{article}
\title{Another leftskip and rightskip example}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=8cm]{geometry}
% Set the value of some paragraph-related parameters
\setlength{\lineskip}{3.5pt}
\setlength{\lineskiplimit}{2pt}
\setlength{\parindent}{20pt}
\setlength{\baselineskip}{12pt}

\begin{document}
\input text.tex % A generated TeX file which defines the macros
% \mytextA and \mytextB which define text for two paragraphs
% Here we change \leftskip and \rightskip to "extremely flexible" glue settings
% within a group created by \begingroup ... \endgroup

\begingroup
\leftskip 0pt plus 1fill
\rightskip 0pt plus 1fill
\mytextB
\endgroup

% Now re-typeset the same paragraph after the group has closed
% causing \leftskip and \rightskip revert to their previous values

\vspace{20pt}
\mytextB

\end{document}
```

&#x20;Open this example as an Overleaf LaTeX project

This example generates the following output:

![Using \leftskip and \rightskip in a group](/files/nOEWp19K8e9gYE93udex)

**Note**: The settings for (effects of) `\leftskip` and `\rightskip` are restricted to the paragraph within the group created by `\begingroup`... `\endgroup`. After the group has been closed, the next paragraph is typeset using LaTeX’s default values for `\leftskip` and `\rightskip`.

### \baselineskip (TeX primitive)

It is generally accepted typesetting practice that lines of text within paragraphs should be equally spaced, except where certain lines contain large elements, such as mathematics or an image, which make it impossible to preserve constant interline spacing for such lines.

TeX/LaTeX provide commands and mechanisms which enable users to exercise some degree of control over interline spacing. One such command is `\baselineskip` which gets, or sets, the value of a parameter that determines the preferred interline spacing (baseline-to-baseline distance) in a typeset paragraph.

To typeset the current value of `\baselineskip` you can write

```latex
\the\baselineskip
```

To set `\baselineskip` to some `value` (a LaTeX length such as `pt`) you can write

```latex
\setlength{\baselineskip}{value}
```

For example, to set `\baselineskip` to `12pt` you can write

```latex
\setlength{\baselineskip}{12pt}
```

We can demonstrate the role of `\baselineskip` by using the following (typical) paragraph:

![An example LaTeX paragraph](/files/ifTxvOJilee8cygRFlhn)

and adding annotations which show the baseline-to-baseline distance controlled by `\baselineskip`:

![An example LaTeX paragraph annotated to show baseline distances](/files/0JZP5bDEwXRo42DeH169)

The diagram also shows the interline “glue”: a calculated amount of white space added between lines—we’ll further discuss this later in the article.

#### \baselineskip and other parameters

`\baselineskip` is one of four core parameters which control the amount of space inserted between lines of a paragraph; the others are:

* `\lineskip`
* `\lineskiplimit`
* `\prevdepth`

Later in the article we’ll explore [*how these four parameters are used*](#paragraph-structure-and-line-space-calculations) to calculate interline glue values.

#### \baselineskip example (fixed space)

The following example opens in Overleaf to create a project containing a file called `text.tex` which defines the commands `\mytextA` and `\mytextB`—both commands typeset a paragraph. For convenience, the Overleaf project uses a small page size because that assists with preparing graphics and images for this help page.

```latex
\documentclass{article}
\title{Demonstrating baselineskip}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=8cm]{geometry}
% Set the value of some paragraph-related parameters (we will discuss these)
\setlength{\lineskip}{3.5pt}
\setlength{\lineskiplimit}{2pt}
\setlength{\parindent}{20pt}
% Set the value of \baselineskip---change the value to see the effect
\setlength{\baselineskip}{12pt}

\begin{document}
\input text.tex % A generated TeX file which defines the macros
% \mytextA and \mytextB, each of which typeset a paragraphs

% Firstly, typeset two paragraphs with the default \baselineskip
\mytextA\mytextB

% Now change \baselineskip to a larger value and typeset
% another paragraph
\setlength{\baselineskip}{24pt}
\mytextA

\end{document}
```

&#x20;Open this example as an Overleaf LaTeX project

This example generates the following output:

![Exploring baselineskip in TeX or LaTeX](/files/jKgtX59ySKVR0Mr6kTkC)

The paragraph on page 2 has widely spaced lines because `\baselineskip` was set to 24pt.

#### \baselineskip example (flexible space)

The following example specifies a `\baselineskip` value which has an extremely flexible (so-called “infinite”) stretch component:

```latex
\baselineskip=12pt plus1fil
```

Because of this flexibility, white space between paragraph lines can stretch by any amount required to fill the page. Such flexibility would result in paragraphs having very different amounts of space between their constituent lines of text, which might not be aesthetically pleasing or easy to read.

```latex
\documentclass{article}
\usepackage{blindtext}
\title{Flexible \texttt{\string\baselineskip} demo}
\author{Overleaf}
\date{January 2022}

\begin{document}

\maketitle
We’ll provide \verb|\baselineskip| with a very flexible ``stretch'' component by assigning the value \texttt{12pt plus1fil}: \verb|\baselineskip=12pt plus1fil|.\baselineskip=12pt plus1fil
\section{Introduction}
Add a paragraph that will now stretch to fill the page. \blindtext

\end{document}
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Flexible+baselineskip+demo\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Ctitle%7BFlexible+%5Ctexttt%7B%5Cstring%5Cbaselineskip%7D+demo%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BJanuary+2022%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cmaketitle%0AWe%E2%80%99ll+provide+%5Cverb%7C%5Cbaselineskip%7C+with+a+very+flexible+%60%60stretch%27%27+component+by+assigning+the+value+%5Ctexttt%7B12pt+plus1fil%7D%3A+%5Cverb%7C%5Cbaselineskip%3D12pt+plus1fil%7C.%5Cbaselineskip%3D12pt+plus1fil+%0A%5Csection%7BIntroduction%7D%0AAdd+a+paragraph+that+will+now+stretch+to+fill+the+page.+%5Cblindtext%0A%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Demonstrating baselineskip glue with infinite flexibility](/files/WqTsU8WwfAWheJnCvMVU)

**A few notes on glue**

Some of the following notes are taken from the Overleaf article [exploring underfull or overfull boxes and badness calculations](https://www.overleaf.com/latex/examples/exploring-underfull-or-overfull-boxes-and-badness-calculations/wpfsjnbkrfhv), reproduced here for convenience.

The white space that TeX inserts between lines of a paragraph, `\baselineskip`, is a form of flexible spacing called *glue*. A glue value can be specified three components:

* a *fixed* amount;
* an amount it can *stretch*;
* an amount it can *shrink*,

Consequently, a `\baselineskip` value can be specified like this:

`\baselineskip`=*fixed amount* **plus** *amount to stretch* **minus** *amount to shrink*

where

* **plus** and **minus** are keywords that TeX engines understand;
* *fixed amount* is referred to as the *normal component* of the glue (also called the *natural width* of the glue);
* *amount to stretch* is referred to as the *stretch component* of the glue;
* *amount to shrink* is referred to as the *shrink component* of the glue.

The *fixed amount* is required for all glue values but *amount to stretch* and *amount to shrink* are both optional—if either, or both, are missing they are set to a value of 0.

Usually, `\baselineskip` glue is specified with a *fixed amount* only, the stretch and shrink components are zero, otherwise paragraph lines would have irregular (variable) spacing, which might not be aesthetically pleasing.

### \offinterlineskip and \nointerlineskip (macros)

These macros are often used to prevent insertion of interline glue between lines of a paragraph. Readers interested in more detail can jump ahead to the relevant article sections which explain how these macros work.

* **`\offinterlineskip`**: See the article section [*Zero-sized interline glue: \offinterlineskip*](#zero-sized-interline-glue-offinterlineskip).
* **`\nointerlineskip`**: See the article section [*Preventing interline glue: \prevdepth and \nointerlineskip*](#preventing-interline-glue-prevdepth-and-nointerlineskip).

## Paragraph structure and line space calculations

Using the capabilities of LuaTeX it is possible to [post-process a typeset paragraph](https://www.overleaf.com/latex/examples/luatex-parsing-typeset-paragraphs/mzbpwxtjshsj) to visualize boundaries of constituent characters (glyphs), lines and glues from which it is constructed. We’ll start with a short sequence of graphics to help visualize the “boxes and glue” model that TeX engines use to typeset text contained in a paragraph.

### Paragraph structure

When TeX typesets a paragraph it treats individual characters as miniature boxes, each with its own width, height and depth and those character-box widths are used to calculate the optimum locations for linebreaks. In addition, space characters contained within the text, and used to separate individual words, are converted to a form of flexible space (glue) which provides the spacing needed to achieve each linebreak.

The following sequence of 7 graphics show the core components of a typeset paragraph: various types of boxes and glue. The first graphic shows a typeset paragraph together with an annotated version which highlights various elements within the paragraph. However, the annotated paragraph contains a lot of information so the subsequent graphics isolate various components to (hopefully) make them easier to understand.

![Paragraphanatomy1b.png](/files/XzYzs8uBhkgMSUuFcdCR)

* The next graphic depicts paragraph lines as gray boxes separated by glue that is represented by horizontal green strips. That glue is calculated to ensure the baseline-to-baseline distance is equal to (i.e., the value of) `\baselineskip`:

![Paragraphanatomy2b.png](/files/ElRUPkTrgexBUBVuKByR)

* The next image represents typeset characters as boxes: to visualize how TeX engines process characters for the purpose of producing linebreaks:

![Paragraphanatomy3.png](/files/AO21qwkEWFwzIS6bHTgv)

* The next image shows boxes within boxes: the larger paragraph lines (boxes) containing smaller boxes (individual characters):

![Paragraphanatomy5.png](/files/sOoikxEsdt0brNb17weX)

* The next image shows the amount of space between words in each line: these inter-word spaces are produced by converting space characters to flexible glues that are stretched or shrunk to produce the correct length for each line of text. Note carefully that the size of these spaces vary from line-to line:

![Paragraphanatomy4.png](/files/Wqscgy6SLEzkdMv891Or)

* The next image combines the character boxes and corresponding glues (space) placed between individual words:

![Paragraphanatomy6.png](/files/7rVOm06aTRKIirjPb1uV)

### Visualizing other types of paragraph glue

The following paragraphs were also typeset and processed using LuaTeX to show other types of glue within, and between, a pair of paragraphs. Note that `\rightskip` and `\leftskip` are both set to 0pt, so they are not shown:

* **`\parskip`** glue (light blue) placed between the two typeset paragraphs;
* individual words are separated by ***interword glue*** (yellow) created by converting space characters in the input to variable-sized white space (glue) in the typeset output. Glue arising from interword spaces is stretched or shrunk to achieve visually pleasing linebreaks;
* **`\baselineskip`** glue (light green) placed between lines—the exact amount of `\baselineskip` glue is calculated using the mechanism discussed below;
* **`\lineskip`** glue (red) being used in the second paragraph—due to the low box contained in the second-to-last line;
* **`\parfillskip`** glue (dark green) placed at the end of the last line in each paragraph.

![](/files/iX4Nl8Byqezrnc9qZHly)

### Dealing with deeper (or taller) lines (boxes)

As shown by graphics in the [previous section](#paragraph-structure), a typeset paragraph is a vertical stack of “boxes”, separated by some white space, which TeX calls “glue”. As the paragraph is processed, and the individual lines (boxes) are stacked, the vertical list (stack) grows in a *downward* direction, toward the bottom of the page. Although TeX/LaTeX try to ensure paragraph lines are stacked with baselines separated by a constant distance of `\baselineskip`, it’s not always possible to achieve that because certain lines can have a larger-than-usual height or depth.

The height and depth of each paragraph line is determined by the maximum distance that line’s content extends above or below the baseline; consequently, paragraphs containing material with a relatively large height or depth, such as inline math or graphics, are likely to produce individual lines with correspondingly large heights and/or depths. For such lines, TeX/LaTeX may be unable to stack them such that their baselines are separated from other lines by the `\baselineskip` amount. Clearly, TeX/LaTeX need a “fallback mechanism” to handle such lines by *calculating* a suitable amount of space to insert between each pair of lines affected by large heights and/or depths.

#### \lineskip and \lineskiplimit (TeX primitives)

That fallback mechanism involves the parameter commands `\lineskip` and `\lineskiplimit` together with a third parameter called `\prevdepth`. Readers interested in further details can jump ahead to the article section [*How the space (glue) between paragraph lines is calculated*](#how-the-space-glue-between-paragraph-lines-is-calculated).

The example project, below, typesets a single paragraph whose last line has a relatively large depth due a shifted text box (`\hbox`). The paragraph is typeset using these settings:

```latex
\setlength{\baselineskip}{12pt}
\setlength{\lineskip}{3.5pt}
\setlength{\lineskiplimit}{2pt}
\setlength{\parindent}{20pt}
```

Use the link below the following code to open an Overleaf project:

```latex
\documentclass{article}
% Use a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=8cm]{geometry}
% Set some important parameters
\setlength{\baselineskip}{12pt}
\setlength{\lineskip}{3.5pt}
\setlength{\lineskiplimit}{2pt}
\setlength{\parindent}{20pt}
% Input file defining \testpar
\input testpar.tex
\title{A sample paragraph for lineskip}
\begin{document}
\testpar % A macro created in the Overleaf project
\end{document}
```

&#x20;[Open this example in Overleaf.](https://www.overleaf.com/docs?engine=\&snip_name\[]=main.tex\&snip\[]=%5Cdocumentclass%7Barticle%7D%0A%25+Use+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D8cm%5D%7Bgeometry%7D%0A%25+Set+some+important+parameters%0A%5Csetlength%7B%5Cbaselineskip%7D%7B12pt%7D%0A%5Csetlength%7B%5Clineskip%7D%7B3.5pt%7D%0A%5Csetlength%7B%5Clineskiplimit%7D%7B2pt%7D%0A%5Csetlength%7B%5Cparindent%7D%7B20pt%7D%0A%25+Input+file+defining+%5Ctestpar+%0A%5Cinput+testpar.tex%0A%5Ctitle%7BA+sample+paragraph+for+lineskip%7D%0A%5Cbegin%7Bdocument%7D%0A%5Ctestpar+%25+A+macro+created+in+the+Overleaf+project%0A%5Cend%7Bdocument%7D\&snip_name\[]=testpar.tex\&snip\[]=%5Cnewcommand%7B%5Ctestpar%7D%7B%5CTeX%7B%7D+uses+the+name+%60%60glue%27%27+to+describe+%60%60flexible+white+space%27%27+used+to+separate+any+typeset+item+which+can+appear+on+the+page.+For+example%2C+individual+words%2C+and+whole+lines%2C+within+a+typeset+paragraph+are+seperated+by+%60%60glue%27%27.+%5CTeX%7B%7D+engines+identify+%28give+a+name+to%29+different+types+of+glue+according+to+where+it+is+being+used.+For+example%2C+each+line+is+separated+by+%5Ctexttt%7B%5Cstring%5Cbaselineskip%7D+glue+or%2C+occasionally%2C+%5Ctexttt%7B%5Cstring%5Clineskip%7D+glue%2C+depending+on+%5CTeX%27s+calculations.+Let%27s+trigger+use+of+%5Ctexttt%7B%5Cstring%5Clineskip%7D+glue+by+adding+an+%5Ctexttt%7B%5Cstring%5Chbox%7D+which+has+a+large+depth+due+to+the+%5Ctexttt%7B%5Cstring%5Clower%7D+command%3B+for+example%2C+the+box%0A+%5Clower5pt%5Chbox%7BLOW+BOX%7D+will+cause+%5CTeX%7B%7D+to+insert+%5Ctexttt%7B%5Cstring%5Clineskip%7D+glue+instead+of+%5Ctexttt%7B%5Cstring%5Cbaselineskip%7D+glue.%5Cpar%7D\&main_document=main.tex)

This example produces the following output:

![Example to demonstrate \lineskip glue](/files/wcyhYAzGzitO2SleLphX)

The following graphic uses an annotated version of the paragraph produced by the previous Overleaf project. Here, we zoom in to focus on the last paragraph line, indicating the use of `\lineskip` glue (shown in red) caused by the depth of the shifted text box:

![Image showing TeX \lineskip glue](/files/WjG66ND0oXJ2H7Ur5dso)

The final line of the paragraph text has a larger-than-usual depth, preventing TeX from maintaining the constant baseline-to-baseline distance specified by the value `\baselineskip` (12pt). As indicated by arrows on the right-hand side of the graphic, TeX/LaTeX try to ensure a fixed distance (12pt) between pairs of lines—the value of `\baselineskip`. However, for the last pair of lines TeX has separated them by an amount greater than 12pt and uses the value of `\lineskip` for the interline glue instead of a value calculated using `\baselineskip`.

The following sections explore and explain the details of TeX’s calculations of interline glue values.

### How the space (glue) between paragraph lines is calculated

For current purposes we’ll *very briefly* mention TeX’s page-construction process, albeit in a highly simplified way! Once TeX has finished typesetting a paragraph, by completing hyphenation and determining linebreaks, you can think of that paragraph data as being stored in a temporary memory location. TeX then needs to move that paragraph data, line-by-line, to a new memory location which stores material destined for the current output page.

When TeX moves the paragraph data, line-by-line, it is, in effect, building a vertical stack of lines (TeX boxes) which grows *downward* toward the bottom of the page. As it moves paragraph lines to the current page TeX tries to ensure those lines will be spaced equally, having consistent vertical (baseline-to-baseline) spacing equal to the value `\baselineskip`. When a new line is transferred to the current page, the TeX engine temporarily records that line’s *depth* because it will be used to calculate the amount of interline glue (white space) between that line and the line placed after it.

#### Glue size calculations

Let’s start by summarizing the interline spacing features provided by TeX engines:

* keeping a constant distance between baselines, a distance equal to `\baselineskip`;
* provide spacing for any lines with a relatively large height or depth;
* a capability to switch off insertion of interline glue—either automatically or under user control. For example:
  * TeX engines automatically disable insertion of interline glue after a rule in vertical mode;
  * the macros `\offinterlineskip` and `\nointerlineskip` allow users to temporarily switch off insertion of interline glue—those macros have different effects, as we’ll see below.

The decision whether to add interline glue and, if so, how much of which type, goes like this:

* Should interline glue be added? TeX decides this by testing whether the *depth of the last line added* to the list is less than the special value of `–1000pt` (points). Note that `–1000pt` is an arbitrary “sentinel” value used internally by TeX engines.
  * **Note**: The value of “depth of the last line added”, which TeX records internally, is also known as the “previous depth”. TeX engines provide the parameter command `\prevdepth`—which can, in certain circumstances, be used to *get* or *set* the value of “previous depth”. The macro `\nointerlineskip` makes use of `\prevdepth`.
* TeX tests whether `depth of previous line is greater than –1000pt`?
  * ***Yes it is*** (need to add glue):
    * calculate the value Δ, where Δ = \baselineskip – (depth of previous line) – (height of next line)
    * compare Δ to the value of `\lineskiplimit`, a parameter used to define the minimum acceptable distance between two lines, as measured by the distance between the bottom of the upper line and the top of the lower line.
    * If Δ < `\lineskiplimit`:
      * the lines are too close so insert the minimum acceptable spacing which is `\lineskip`
    * If Δ >= `\lineskiplimit`:
      * the lines are not too close so use Δ as the amount of glue to insert
  * ***No it is not*** (do not add glue):
    * Add the next line (box) without inserting any glue

The following graphic summarizes the interline glue process:

![How TeX detemines interline glue values](/files/ORMTu9GOLydsUMKFlBJz)

### An example of interline glue calculations

In the following example we assume that TeX/LaTeX is using the following command parameter values:

```latex
\baselineskip=12pt
\lineskip=3.5pt
\lineskiplimit=2pt
```

We’ll look at the interline glue calculation for the first two lines of this paragraph:

![OLV2glue-calcs-step0.png](/files/2kMt9V76i60PwdyGJL9L)

In the next image, the TeX engine has processed the first paragraph line and moved it to the vertical list it is building. It keeps track of that line’s depth (`d<sub>1</sub>`) which is `2.1528` (points):

![OLV2glue-calcs-step1.png](/files/Si7ynDsFZFn848M2UoNs)

Next, TeX is ready to add a second line to the list it is building: that line has a height (`h<sub>2</sub>`) which is `6.9444` (points) and, incidentally, a depth, `d<sub>2</sub>` of `0` (points):

![OLV2glue-calcs-step2.png](/files/KuyDLldzw7nvvBVuj3CF)

At this point, TeX needs to calculate the amount of space (glue, `g<sub>1</sub>`) to insert between these two lines:

![OLV2glue-calcs-step3.png](/files/GtWdSJaS6fv1YE7D8Xti)

The following image shows the glue calculations for this pair of lines:

![OLV2glue-calcs-stepA3.png](/files/zJvFT48cOMBXUIDyrKY8)

The final image shows the two lines moved across to the current page with the calculated amount of interline glue placed between them:

![OLV2glue-calcs-step5.png](/files/8nIJLlgIjphkTqLrv9gA)

### Yet another parameter: \prevdepth

As noted above, when TeX is creating a vertical stack (list) of boxes, it stores the depth of the last box added to that list. That stored depth value is known as the “previous depth” which can be accessed via the parameter command `\prevdepth`.

The `\prevdepth` command can be used ***only*** when TeX is in a vertical mode; i.e., between paragraphs or inside vertical boxes: `\vbox`, `\vtop` or `\vcenter` (note: `\vcenter` boxes can only be used in math mode).

`\prevdepth` provides read and write access to the value of “previous depth”:

* to read access the current value of `\prevdepth` you can write:

```latex
\the\prevdepth
```

* to set the current value of `\prevdepth` to `some value`, a length in points, mm, etc, you can write:

```latex
\setlength{\prevdepth}{some value}
```

If you try to use \verb`\prevdepth` in circumstances it was not designed for, such as within a paragraph or inside an `\hbox` you’ll get an error

```latex
Improper \prevdepth.
```

with additional information telling you it can only be used in vertical mode.

#### Preventing interline glue: \prevdepth and \nointerlineskip

One use of `\prevdepth` is to *prevent* TeX performing the baseline calculations used to add interline glue between items in a vertical list, such as the lines of a paragraph. Using `\prevdepth` to represent `depth of previous line` we can re-state the glue calculations (pictured above) as follows:

```latex
if(\prevdepth > –1000pt)
{
     Δ = \baselineskip — \prevdepth — (height of current line)

     if(Δ < \lineskiplimit)
       interline glue = \lineskip
     else
       interline glue = Δ
}
else
{
     Stack the box without adding
     any interline glue
}
```

Internally, TeX engines recognize a so-called “sentinel” value of `\prevdepth` which can be used to disable calculating and adding interline glue. That sentinel value is `–1000pt`, which can be seen in the first line of the pseudo-code above:

```latex
if(\prevdepth > –1000pt)
```

TeX will not add interline glue unless `\prevdepth` is greater than `–1000pt`— which provides the mechanism used by the `\nointerlineskip` macro to prevent baseline glue being added between the next pair of boxes in a vertical list.

`\nointerlineskip` has a definition equivalent to:

```latex
\def\nointerlineskip{
\prevdepth–1000pt
}
```

Note that `\nointerlineskip` provides a *one-off deactivation* of interline glue calculations because the value of `\prevdepth` is continually updated as new boxes are added to the current vertical list, as demonstrated in the following example:

```latex
\noindent The following \verb|\hbox|es are processed when \TeX{} is in so-called \textit{outer vertical mode}. After processing (typesetting), these boxes are appended to the current page and stacked vertically with interline glue inserted between them:

\hbox{j}
\hbox{p}
\hbox{g}

Now, immediately after after the box \verb|\hbox{j}|, we set \verb|\prevdepth| to \texttt{-1000pt} which prevents interline glue being placed between the boxes \verb|\hbox{j}| and \verb|\hbox{p}|:

\hbox{j}\setlength{\prevdepth}{-1000pt}
\hbox{p}
\hbox{g}

Observe that interline glue \textit{is} placed between the boxes \verb|\hbox{p}| and \verb|\hbox{g}| because the value of \verb|\prevdepth| is updated after \verb|\hbox{p}| is processed and added to the list: the value of \verb|\prevdepth| becomes the depth of the box \verb|\hbox{p}|. When \verb|\hbox{g}| is added to the vertical list the value of \verb|\prevdepth| is no longer \texttt{-1000pt}; consequently, interline glue can now be added.
```

&#x20;[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=One-shot+use+of+nointerlineskip\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D10cm%5D%7Bgeometry%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cbaselineskip%7D%7B14pt%7D%0A%5Csetlength%7B%5Cparskip%7D%7B1pt%7D%0A%5Csetlength%7B%5Cparindent%7D%7B0pt%7D%0A%25+A+convenience+macro+to+typeset+%5Cprevdepth+in+an+%5Chbox%2C+although+TeX+has+to+be%0A%25+in+a+vertical+mode+when+this+macro+is+used.%0A%5Cnoindent+The+following+%5Cverb%7C%5Chbox%7Ces+are+processed+when+%5CTeX%7B%7D+is+in+so-called+%5Ctextit%7Bouter+vertical+mode%7D.+After+processing+%28typesetting%29%2C+these+boxes+are+appended+to+the+current+page+and+stacked+vertically+with+interline+glue+inserted+between+them%3A%0A%0A%5Chbox%7Bj%7D%0A%5Chbox%7Bp%7D%0A%5Chbox%7Bg%7D%0A%0ANow%2C+immediately+after+after+the+box+%5Cverb%7C%5Chbox%7Bj%7D%7C%2C+we+set+%5Cverb%7C%5Cprevdepth%7C+to+%5Ctexttt%7B-1000pt%7D+which+prevents+interline+glue+being+placed+between+the+boxes+%5Cverb%7C%5Chbox%7Bj%7D%7C+and+%5Cverb%7C%5Chbox%7Bp%7D%7C%3A+%0A%0A%5Chbox%7Bj%7D%5Csetlength%7B%5Cprevdepth%7D%7B-1000pt%7D%0A%5Chbox%7Bp%7D%0A%5Chbox%7Bg%7D%0A%0AObserve+that+interline+glue+%5Ctextit%7Bis%7D+placed+between+the+boxes+%5Cverb%7C%5Chbox%7Bp%7D%7C+and+%5Cverb%7C%5Chbox%7Bg%7D%7C+because+the+value+of+%5Cverb%7C%5Cprevdepth%7C+is+updated+after+%5Cverb%7C%5Chbox%7Bp%7D%7C+is+processed+and+added+to+the+list%3A+the+value+of+%5Cverb%7C%5Cprevdepth%7C+becomes+the+depth+of+the+box+%5Cverb%7C%5Chbox%7Bp%7D%7C.+When+%5Cverb%7C%5Chbox%7Bg%7D%7C+is+added+to+the+vertical+list+the+value+of+%5Cverb%7C%5Cprevdepth%7C+is+no+longer+%5Ctexttt%7B-1000pt%7D%3B+consequently%2C+interline+glue+can+now+be+added.%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Example demonstrating of TeX’s parameter \prevdepth](/files/FVvM26aUxQYHokYEOItx)

#### Zero-sized interline glue: \offinterlineskip

It is possible to remove all interline spacing via the macro command `\nointerlineskip`, which has a definition equivalent to:

```latex
\def\offinterlineskip{%
\baselineskip=-1000pt
\lineskip=0pt
\lineskiplimit=\maxdimen
}
```

Note that `\maxdimen` is `16383.99998pt`, the largest length that TeX can use.

The following graphic shows the core interline glue calculations and the various parameter values used by the macro `\nointerlineskip`:

![offinterlineskip](/files/MKFEtJ7IfvZjoXs9ujsZ)

The following graphic shows the pseudo-code fragment which results from substituting the `\nointerlineskip` macro values into the glue calculations. It demonstrates how the `\nointerlineskip` macro works by setting values for `\baselineskip` and `\lineskiplimit` such that the interline glue will always be `\lineskip` glue of `0pt`.

![offinterlineskip](/files/zeXGmnyuSeOcbeFdkU5D)

#### \offinterlineskip and non-zero \lineskip

The `\nointerlineskip` macro sets `\lineskip` to zero but, as the following Overleaf project demonstrates, you can combine `\nointerlineskip` with non-zero values of `\lineskip` to achieve line spacing effects.

```latex
\documentclass{article}
\title{Demonstrating non-zero lineskip}
% Choose a conveniently small page size
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=8cm]{geometry}
\begin{document}

\offinterlineskip % This sets \lineskip to 0pt

\setlength{\lineskip}{5pt} % We want non-zero \lineskip

\input text.tex % A generated TeX file which defines the macros
% \mytextA and \mytextB, each of which typesets a paragraph

\mytextA % Typeset a paragraph

% Now change \lineskip to a flexible glue value and typeset
% another paragraph

\setlength{\lineskip}{5pt plus5pt minus5pt}

\mytextA

\end{document}
```

&#x20;Open this example as an Overleaf LaTeX project

This example generates the following output:

![Demonstrating LaTeX’s \offinterlineskip macro](/files/I7oVVLzM04Cz7ecuTtzE)

You can localize the effect(s) of using `\offinterlineskip` and `\lineskip` (and other spacing commands) by enclosing them in a group:

```latex
\begingroup
\offinterlineskip
\setlength{\lineskip}{5pt}
...your paragraph(s) here

\endgroup
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/formatting/04-articles-how-to-change-paragraph-spacing-in-latex.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
