math add tag
CarLaTeX
How can I have the same spacing after and before `cases` as after and before an usual equation, when the text is double spacing but I don't want double spacing in `cases`?


```
\documentclass{book}
\usepackage{setspace}

\usepackage{mathtools}
\usepackage{physics}
\usepackage{amssymb}
\newcommand{\punc}[1]{\,\text{#1}}
\begin{document}
\doublespacing
Something before Something before Something before Something before Something before Something before Something before Something before 
\[\setstretch{1}
L_i =\begin{cases}
1\text{,}&\text{when }X_i \leq \xi_i\text{, with probability } p\\
0\text{,}&\text{otherwise, with probability } 1-p\punc{.}
\end{cases}
\]
something after something after something after something after something after
\[x+y=z
\]
something after something after something after something after something after
\end{document}
```
![2020-07-29 (2).png](/image?hash=0fd6a71a47f897bbdf0a1513b9724a755f2962f29a39fee789e25349b161b4fd)
Top Answer
Circumscribe
You can accomplish this by setting `\baselinestretch` back to `1` inside the definition of the `cases` environment. This is a multiplier for the distance between lines in a paragraph (and also between the rows of the `cases` environment) and it was set to `1.667` by `\doublespacing`.

To patch `cases`, add any one of the following three snippets to your preamble (whichever you prefer):


```
\usepackage{etoolbox}
\AtBeginEnvironment{cases}{\renewcommand\baselinestretch{1}\selectfont}
```

```
\let\originalcases\cases
\renewcommand\cases{%
  \renewcommand\baselinestretch{1}\selectfont
  \originalcases
}
```

```
\edef\cases{%
  \unexpanded{\renewcommand\baselinestretch{1}\selectfont}%
  \unexpanded\expandafter{\cases}%
}
```

Note: 
* The change to `\baselinestretch` only takes effect after `\selectfont` is called, which is why that command is there.
* Simply putting  `\renewcommand\baselinestretch{1}\selectfont` inside the `cases` environment doesn't work because its scope will be limited to just the first cell of the environment.
* Putting `\renewcommand\baselinestretch{1}\selectfont` in the equation itself (or changing `\everydisplay` to put it in every display equation) won't affect the spacing around the the first equation, but it will reduce the skip above (but not below) the second equation. The spacing around the first is unaffected because it has a very tall line (due to the cases) that is already placed more than the stretched `\baselineskip` below the previous baseline. (So don't do this.)

### Demonstration

```
\documentclass{book}
\usepackage{setspace}

\usepackage{mathtools}
\usepackage{physics}
\usepackage{amssymb}
\newcommand{\punc}[1]{\,\text{#1}}

\usepackage{etoolbox} %% <- added
\AtBeginEnvironment{cases}{\renewcommand\baselinestretch{1}\selectfont} %% <- added

\begin{document}
\doublespacing
Something before Something before Something before Something before Something before Something before Something before Something before 
\[ %% <- \setstretch{1} removed
L_i =\begin{cases}
1\text{,}&\text{when }X_i \leq \xi_i\text{, with probability } p\\
0\text{,}&\text{otherwise, with probability } 1-p\punc{.}
\end{cases}
\]
something after something after something after something after something after
\[x+y=z
\]
something after something after something after something after something after
\end{document}
```

![casesspace.png](/image?hash=daae31920d2944c6d42c1151ba18e4b94a9feb11066424d6e6fea2b0b1ff2bda)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.