TransWikia.com

inline spacing within the `cases` command when document is in doublespace mode

TeX - LaTeX Asked on October 3, 2021

For journal submissions, we obviously have to use doublespace mode. But I don’t want to take up even more of the page using a multi-branch cases command, which by default puts double spaces between each branch. Obviously one can manually reduce the gap between branches with [-xpt] at the end of each branch, but it’s incredibly kludgy and fragile and messes up the space between the current line and the following one. I’m wondering if there’s a package or a nice macro that would shrink the gaps in a robust way and manage the vertical height of the left brace. Here’s an MWE where the default spacing within the cases command is ridiculous. Thanks!

documentclass{amsart}
usepackage{lipsum}
usepackage{setspace}
begin{document}
doublespacing
lipsum[1]
$x = 
begin{cases} 
a & text{if } x < -3 
b & text{if } -2 < x < 0 
c & text{if } 0 < x < 2 
d & text{if } x > 2 
end{cases}
$
lipsum[1]
end{document}

3 Answers

Here's a version that redefines the cases environment to temporarily switch to single line spacing within the environment. The extra definition of new@setfontsize is only necessary to suppress a warning about setting text commands in math mode; it's otherwise the same as the original definition.

This pattern should be easily adaptable for other math environments, if necessary.

documentclass{amsart}
usepackage{lipsum}
usepackage{setspace}

makeatletter
newcommandnew@setfontsize[3]{%
    ifx protect @typeset@protect let @currsize #1fi fontsize {#2}{#3}selectfont
}
letorig@setfontsize@setfontsize
letorig@casescases
letendorig@casesendcases

renewenvironment{cases}{%
    let@setfontsizenew@setfontsize
    setstretch{setspace@singlespace}%
    letsetfontsizeorig@setfontsize
    orig@cases
}{%
    endorig@cases
}
makeatother

begin{document}
doublespacing
lipsum[1]
$x = 
begin{cases} 
a & text{if } x < -3 
b & text{if } -2 < x < 0 
c & text{if } 0 < x < 2 
d & text{if } x > 2 
end{cases}
$
lipsum[1]
end{document}

enter image description here

Correct answer by siracusa on October 3, 2021

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, you can add the following snippet to your preamble:

usepackage{etoolbox}
AtBeginEnvironment{cases}{renewcommandbaselinestretch{1}selectfont}

Demonstration

documentclass{amsart}
usepackage{lipsum}
usepackage{setspace}

usepackage{etoolbox} %% <- added
AtBeginEnvironment{cases}{renewcommandbaselinestretch{1}selectfont} %% <- added

begin{document}
doublespacing
lipsum[1]
$x = 
begin{cases} 
a & text{if $x < -3$} 
b & text{if $-2 < x < 0$} 
c & text{if $0 < x < 2$} 
d & text{if $x > 2$}
end{cases}
$
lipsum[1]
end{document}

output


Notes:

  • The change to baselinestretch only takes effect after selectfont is called, which is why that command is there.
  • Simply putting renewcommandbaselinestretch{1}selectfont inside the cases environment doesn't work because its scope will be limited to just the first cell of the environment.

Answered by Circumscribe on October 3, 2021

Rather than redefining cases to use singlespacing or setstretch{1}, I believe it's better to correctly set the arraystretch.

Something similar should probably also be done for array, but one can use fixarraystretch{<factor>} everywhere.

documentclass{amsart}
usepackage{lipsum}
usepackage{setspace}
usepackage{xfp,etoolbox}

makeatletter
patchcmd{env@cases}
  {defarraystretch{1.2}}
  {fixarraystretch{1.2}}
  {}{}
makeatother
newcommand{fixarraystretch}[1]{%
  edefarraystretch{fpeval{#1/(baselinestretch)}}%
}

begin{document}
doublespacing
lipsum[1]
$x = 
begin{cases} 
a & text{if } x < -3 
b & text{if } -2 < x < 0 
c & text{if } 0 < x < 2 
d & text{if } x > 2 
end{cases}
$
lipsum[1]
end{document}

enter image description here

Just a final comment: using double spacing for submissions is a relic of the past; nowadays everybody receives PDF files and leaving space for annotations makes little sense; it just hinders reading the document on the screen.

Answered by egreg on October 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP