4

What would be the best formatting of the following align and cases where the middle case has a very long math equation?

\begin{align*}
      V_{ijk}& = \begin{cases}
          \dfrac{y_u+y_l}2 - \dfrac{x_u+x_l}2,& \text{if }x_u < y_l\\[15pt]
          \dfrac1C \bigg[\dfrac{x_u^3-y_l^3}{6}+\dfrac{y_l^2+x_u^2}{2}x_l + (x_u-y_l)\dfrac{x_l^2}{2}+ \dfrac{y_u^2-x_u^2}{2}(x_u-x_l)& - (y_u-x_u)\dfrac{x_u^2-x_l^2}{2} \bigg],
          \\[12pt]& \text{if }x_u\in\left[y_l,y_u\right]\\[15pt]
          \dfrac1{x_u-x_l}\bigg[\dfrac{(y_u+y_l)^2}6 - \dfrac{y_u+y_l}2 x_l + \dfrac{x_l^2}2\bigg],& \text{otherwise}
      \end{cases}
\end{align*}

The main default of this current workaround which is nearly ok, is that there is an extra space before -(y_u-x_u) that is annoying. Note that I put the second if text under second equation because it would be too width for my memoir otherwise. Please favour simpliest solutions if possible :)

7

with \mfrac from nccmath and multlined from the mathtools package:

enter image description here

\documentclass{article}
\usepackage{mathtools, nccmath}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\[
V_{ijk} = \begin{cases} 
  \mfrac{y_u+y_l}{2} - \mfrac{x_u+x_l}{2},  &\text{if }x_u < y_l    \\[3ex]
    \begin{multlined} 
    \mfrac{1}{C} \bigg[\mfrac{x_u^3-y_l^3}{6}+\mfrac{y_l^2+x_u^2}{2}x_l
      + (x_u-y_l)\mfrac{x_l^2}{2}\\[-2ex]
      + \mfrac{y_u^2-x_u^2}{2}(x_u-x_l) - (y_u-x_u)\mfrac{x_u^2-x_l^2}{2} \biggr]
    \end{multlined},
    & \text{if }x_u\in [y_l,y_u ]
    \\[5ex]
    \mfrac{1}{x_u-x_l}\biggl[\mfrac{(y_u+y_l)^2}{6} - \mfrac{y_u+y_l}{2} x_l
    + \mfrac{x_l^2}{2}\biggr],& \text{otherwise}
  \end{cases}
 \]
\end{document}
  • 1
    Wow impressive! With x_u\in\left[y_l,y_u\right] that is above what I expected – JKHA Aug 14 at 13:38
  • 1
    Upvote for to share \mfrac and \multlined, as these are new to me.... – MadyYuvi Aug 14 at 13:38
  • @JKHA, oh this automatic replacement of left[ with \biggl[ ... corrected now – Zarko Aug 14 at 14:56
5

I'm pretty sure it is a duplicate. But it is also easy to solve using aligned

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
  V_{ijk}& = \begin{cases} \dfrac{y_u+y_l}2 - \dfrac{x_u+x_l}2,&
    \text{if }x_u < y_l
    \\[15pt]
    \begin{aligned}[b]
      &\dfrac1C \bigg[\dfrac{x_u^3-y_l^3}{6}+\dfrac{y_l^2+x_u^2}{2}x_l
      + (x_u-y_l)\dfrac{x_l^2}{2}
      \\
      &+ \dfrac{y_u^2-x_u^2}{2}(x_u-x_l) -
      (y_u-x_u)\dfrac{x_u^2-x_l^2}{2} \bigg]
    \end{aligned},
    & \text{if }x_u\in\left[y_l,y_u\right]
    \\[15pt]
    \dfrac1{x_u-x_l}\bigg[\dfrac{(y_u+y_l)^2}6 - \dfrac{y_u+y_l}2 x_l
    + \dfrac{x_l^2}2\bigg],& \text{otherwise}
  \end{cases}
 \end{align*}
\end{document}
  • I thought it would be less readable wrapping my second equation, but probably I was wrong – JKHA Aug 14 at 13:02
  • 1
    @JKHA it is pretty standard and it does fint on the paper. BTW: next time please provide a full minimal example including document class and minimal preamble like I do above. It makes it a lot faster for others to help you. – daleif Aug 14 at 13:07
  • All right, I'll do it! – JKHA Aug 14 at 13:15
4

My suggestion is not to use cases, because it increases the interline spaces also inside nested alignments.

Using multlined for the long middle equation does the job.

\documentclass{article}
\usepackage{amsmath,mathtools}

\begin{document}

\begin{equation*}
V_{ijk} = \left\{
\begin{aligned}
& \dfrac{y_u+y_l}2 - \dfrac{x_u+x_l}2, && \text{if }x_u < y_l
\\[2ex]
& \begin{multlined}[b]
    \dfrac{1}{C} \biggl[
      \dfrac{x_u^3-y_l^3}{6}+\dfrac{y_l^2+x_u^2}{2}x_l + (x_u-y_l)\dfrac{x_l^2}{2} \\
      + \dfrac{y_u^2-x_u^2}{2}(x_u-x_l) - (y_u-x_u)\dfrac{x_u^2-x_l^2}{2}
    \biggr],
  \end{multlined} && \text{if }x_u\in [y_l,y_u]
\\[2ex]
& \dfrac{1}{x_u-x_l}\biggl[
    \dfrac{(y_u+y_l)^2}6 - \dfrac{y_u+y_l}2 x_l + \dfrac{x_l^2}2
  \biggr], && \text{otherwise}
\end{aligned}
\right.
\end{equation*}

\end{document}

enter image description here

Avoid code such as \frac1C that's hard to read and to maintain. Also note \biggl and \biggr instead of the unqualified \bigg.

Also avoid align for single equations (which this is an example of).

  • "because it increases the interline spaces also inside nested alignments". Sure? Yesterday's conversation was quite about this point: aligned does not care about being inside cases. Am I misunderstanding the statement? – campa Aug 14 at 15:37
  • @campa Uhm, that's quite bizarre indeed, but I guess multlined is affected. – egreg Aug 14 at 15:40
  • Ah, good point, I missed that you were using multlined. – campa Aug 14 at 15:44
4

Here's a solution that employs a dcases* environment instead of the cases environment. The d in dcases denotes "display style"; this means, among other things, that one can write \frac instead of \dfrac in order to get "large" fraction terms.

enter image description here

Note that I've removed unnecessary \left and \right directives.

\documentclass{article}
\usepackage{mathtools} % for 'dcases*' environment

\begin{document}
\[
V_{ijk} = 
\begin{dcases*} 
\frac{y_u+y_l}{2} - \frac{x_u+x_l}{2}\,,
   &if $x_u < y_l$\\[1ex]
\begin{aligned}[b]
&\frac{1}{C} \biggl[
   \frac{x_u^3-y_l^3}{6}+\frac{y_l^2+x_u^2}{2}x_l
   + (x_u-y_l)\frac{x_l^2}{2}\\
&\quad + \frac{y_u^2-x_u^2}{2}(x_u-x_l) 
   - (y_u-x_u)\frac{x_u^2-x_l^2}{2} \,\biggr]\,,
\end{aligned}
   &if $x_u\in[y_l,y_u]$ \\[1ex]
\frac{1}{x_u-x_l} \biggl[ 
   \frac{(y_u+y_l)^2}{6} 
   - \frac{y_u+y_l}{2} x_l 
   + \frac{x_l^2}{2} \,\biggr]\,,
   & otherwise
\end{dcases*}
\]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.