Compress cases environment horizontally

cases

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.

Best Answer

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

Related Question