GeneralSingle line spacing for the cases environment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
olly78
Posts: 14
Joined: Wed Sep 24, 2008 10:57 am

Single line spacing for the cases environment

Post by olly78 »

Hi all

I'm posting a solution to a problem I had because I couldn't find the exact solution on the web, but managed to work it out myself from a similar solution posted on these boards for the quotation environment.

If you're writing a document with double spacing you will find that when you use the "cases" environment in equations the cases will also be double spaced, which looks ungainly. To solve the problem I added the 3 lines of code in the preamble of this minimal working example (MWE)

Code: Select all

\documentclass[a4paper,11pt]{report}
\usepackage{amsmath}
\usepackage{setspace}

\let\oldcases\cases
\let\oldendcases\endcases
\renewenvironment{cases}{\setstretch{1}\oldcases}{\oldendcases}

\begin{document}
\doublespace

blah blah ajweh uhef kjhsdfkj hlkjdhfkj hdfkjhdfs kjhdksl fjhkjsdfhklj sdfkljh fhksdhjkh dsf hfsdkljhsdf kjhsdf jhf ksdfkjhdfs kjhf sdfkhdsfkh eroihekhf fadsho  fshlksd sef klhflk khjf kjh 
\begin{equation}
A = \begin{cases} a & b \\ c & d \end{cases}
\end{equation}
blah blah ajweh uhef kjhsdfkj hlkjdhfkj hdfkjhdfs kjhdkslf jhkjsdfhklj sdfkljh fhksdhjkh dsf hfsdkljhsdf kjhsdf jhf ksdfkjhdfs kjhf sdfkhdsfkh eroihekhf fadsho  fshlksd sef klhflk khjf kjh 
\end{document}
To see the effect without the fix, comment out the line starting "\renewenvironment".

Olly

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Single line spacing for the cases environment

Post by localghost »

I think that a redefinition of the cases environment is not really needed. Take the following example.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[centering,includeheadfoot,margin=2cm]{geometry}
\usepackage{lmodern}
\usepackage[doublespacing]{setspace}
\usepackage{blindtext}
\usepackage{amsmath}

\parindent0em

\begin{document}
  \blindtext
  \begin{equation}
    \setstretch{1}
    A =
    \begin{cases}
      a & b \\
      c & d
    \end{cases}
  \end{equation}
  \blindtext
\end{document}

Best regards
Thorsten¹
olly78
Posts: 14
Joined: Wed Sep 24, 2008 10:57 am

Single line spacing for the cases environment

Post by olly78 »

localghost wrote:I think that a redefinition of the cases environment is not really needed.
I agree. However, that solution requires code before every instance of the cases environment. I wanted a solution that wouldn't need me to do that, so that if you change your mind, or want a different stretch factor, you don't need to go through your document changing it everywhere. So not needed, yes, but preferable (in most cases ;-) ), yes also.
Post Reply