4

I currently have the following cases environment:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{lipsum}

\begin{document}

\lipsum[66]
\[
G(x,u) = \begin{cases}
-\dfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u) - 2\cosh (\pi + x - u)}{4\sinh \pi} & \text{for \(0 \le x \le u \le \pi\)}\vspace{0.25em}\\
-\dfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u) - 2\cosh (\pi - x + u)}{4\sinh \pi} & \text{\phantom{for} \(0 \le u \le x \le \pi\).}
\end{cases}
\]

\end{document}

but it produces a result that sticks out into the margin:

current LaTeX output

I think the natural way to fix this would be to intersperse the expressions and conditions in the following way (apologies for bad image editing, but hopefully it's clear what I mean):

desired LaTeX output

Is there a straightforward way of achieving this with cases or similar?


This is similar to the desired output in this question, which used a hack to produce something along the right lines. But the answers in that case focused on splitting the expressions, which doesn't work well for me.

5
  • 3
    Please extend your code fragment to a MWE.
    – Zarko
    Mar 25, 2022 at 11:24
  • Please tell us how wide the textblock is and which font size you employ (10pt?, 11pt?, 12pt?, someething else?).
    – Mico
    Mar 25, 2022 at 11:33
  • @Zarko Done (based on your example below – thanks). Mar 25, 2022 at 11:58
  • @Mico 10pt, A4 paper and default margins for article class. The important thing is that the expressions fit into the column on their own, but the conditions don't fit next to them. Mar 25, 2022 at 12:00
  • Meanwhile you receive two answers ... are non of them is not worth to be upvoted or even the best one (for your expectation) to be accepted?
    – Zarko
    Mar 25, 2022 at 12:26

5 Answers 5

5

You can move the condition to a new line:

\documentclass{article}
\usepackage{mathtools}
\usepackage{lipsum}

\begin{document}

\lipsum[66]
\begin{equation}
G(x,u) = \begin{cases}
-\dfrac{\cosh(\pi-x-u)+\cosh(\pi+x+u)-2\cosh(\pi+x-u)}{4\sinh\pi} & \\
                     & \makebox[0pt][r]{for $0 \le x \le u \le\pi$} \\[2ex]
-\dfrac{\cosh(\pi-x-u)+\cosh(\pi+x+u)-2\cosh(\pi-x+u)}{4\sinh\pi} & \\
                     & \makebox[0pt][r]{$0\le u\le x\le\pi$}
\end{cases}
\end{equation}

\end{document}

enter image description here

7

Since there is a lengthy common expression, you could do the following:

enter image description here

In the following definition, let $C=\cosh(\pi-x-u)+\cosh(\pi+x+u).$
\[
G(x,u) = \begin{cases}
-\dfrac{C - 2\cosh (\pi + x - u)}{4\sinh \pi} & \text{for \(0 \le x \le u \le \pi\)}\vspace{0.25em}\\
-\dfrac{C - 2\cosh (\pi - x + u)}{4\sinh \pi} & \text{\phantom{for} \(0 \le u \le x \le \pi\).}
\end{cases}
\]
1
  • Would the downvoter care to explain why this is not a useful answer?
    – Sandy G
    Mar 29, 2022 at 15:26
5

I propose this variant layout, based on the fleqn environment and the mediumsized fractions from nccmath:

    \documentclass[a4paper]{article}
    \usepackage{amsmath, mathtools}
    \usepackage{nccmath}
    \usepackage{lipsum}
    \begin{document}

    \lipsum[66]
    \begin{fleqn}
    \[
    \begin{aligned}
     & G(x,u)= \\
     & \begin{cases}\begin{alignedat}{2}
     & -\mfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u) - 2\cosh (\pi + x - u)}{4\sinh \pi} &\qquad \text{for } & 0 \le x \le u \le \pi, \\[2ex]
     & -\mfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u) - 2\cosh (\pi - x + u)}{4\sinh \pi} & & 0 \le u \le x \le \pi.
    \end{alignedat}
    \end{cases}
    \end{aligned}
    \]
    \end{fleqn}

    \end{document} 

enter image description here

4

One possible solution is use of the \splitfrac{ defined in the mathtools package:

enter image description here

\documentclass{article}
\usepackage{mathtools}
\usepackage{lipsum}

\begin{document}
\lipsum[66]
\begin{equation}
G(x,u) = \begin{cases}
-\dfrac{\splitfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u)}
                  {- 2\cosh (\pi + x - u)}}
       {4\sinh \pi}     & \text{for \(0 \le x \le u \le \pi\)}\vspace{0.25em}\\[3ex]
-\dfrac{\splitfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u)} 
                  {- 2\cosh (\pi - x + u)}}
       {4\sinh \pi}     & \text{\phantom{for} \(0 \le u \le x \le \pi\).}
\end{cases}
\end{equation}
\end{document}

However, if you define\textwidth with `geometry package, for example, as is done in the next MWE, that your equation nice fit on page:

\documentclass{article}
\usepackage{geometry}
\usepackage{mathtools}
\usepackage{lipsum}

\begin{document}
\lipsum[66]
\begin{equation}
G(x,u) = \begin{cases}
-\dfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u) - 2\cosh (\pi + x - u)}
       {4\sinh \pi}     & \text{for \(0 \le x \le u \le \pi\)}\vspace{0.25em}\\[3ex]
-\dfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u) - 2\cosh (\pi - x + u)}
       {4\sinh \pi}     & \text{\phantom{for} \(0 \le u \le x \le \pi\).}
\end{cases}
\end{equation}
\end{document}

enter image description here

So, please consider my comment below your question!

4

I endorse your idea, with a few fixes.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
G(x,u) = \left\{
  \begin{aligned}
    -\dfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u) - 2\cosh (\pi + x - u)}{4\sinh \pi}
    \qquad
    \\[-1ex]
    \text{for \(0 \le x \le u \le \pi\),}
    \\[2ex]
    -\dfrac{\cosh (\pi - x - u) + \cosh(\pi + x + u) - 2\cosh (\pi - x + u)}{4\sinh \pi}
    \qquad
    \\[-1ex]
    \text{for \(0 \le u \le x \le \pi\).}
  \end{aligned}
\right.
\]

\end{document}

enter image description here

However, you can do it without cases:

\[
G(x,u)=
  -\frac{\cosh (\pi - x - u) + \cosh(\pi + x + u) - 2\cosh (\pi - \lvert x - u\rvert)}
        {4\sinh \pi}
\]

enter image description here

2
  • 1
    Thanks. This looks like the best option so far. The form using $\lvert x-u \rvert$ is actually the previous step in the calculation, but by considering the two cases $x<u$ and $x>u$ it's possible to simplify slightly further. (These are lecture notes for second-year undergraduates, so I'm showing some detail of the algebra.) Mar 25, 2022 at 13:38
  • 1
    @StephenPowell In that case I'd avoid the cases: first you analyze what happen for ux and then for xu.
    – egreg
    Mar 25, 2022 at 13:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .