3

I am trying to align an equation within the cases environment like so:

\begin{equation}
    R_i=
    \begin{cases}
        2G_{\frac{i}{2} - 1}  &= \frac{i^2 - 2i}{4}, & \text{if}\ 2 | i \\
        2G_{\frac{i - 1}{2} - 1} + \frac{i-1}{2}  &= \frac{i^2 - 2i + 1}{4}, & \text{otherwise}.
    \end{cases}
\end{equation}

Unfortunately this errors with

Extra alignment tab has been changed to \cr. [...\frac{i}{2} - 1} & = \frac{i^2 - 2i}{4}, &]

How would I go about having two alignment tabs in this case?

it works without the extra &

\begin{equation}
    R_i=
    \begin{cases}
        2G_{\frac{i}{2} - 1}  = \frac{i^2 - 2i}{4}, & \text{if}\ 2 | i \\
        2G_{\frac{i - 1}{2} - 1} + \frac{i-1}{2}  = \frac{i^2 - 2i + 1}{4}, & \text{otherwise}.
    \end{cases}
\end{equation}

enter image description here

1
  • Do you really need alignment at =?
    – egreg
    Commented Feb 1, 2018 at 16:27

1 Answer 1

6

You can use aligned or alignedat. But, in my opinion, a plain dcases (requires mathtools) is the best choice.

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

\begin{document}

\begin{equation}
R_i=
\begin{cases}
  \begin{aligned}
  2G_{\frac{i}{2} - 1}                   &= \frac{i^2-2i}{4},   && \text{if $2\mid i$}
  \\
  2G_{\frac{i-1}{2} - 1} + \frac{i-1}{2} &= \frac{i^2-2i+1}{4}, && \text{otherwise}.
  \end{aligned}
\end{cases}
\end{equation}

\begin{equation}
R_i=
\begin{cases}
  \begin{alignedat}{3}
  &2G_{\frac{i}{2} - 1}                   &&= \frac{i^2-2i}{4},
  &\quad& \text{if $2\mid i$}
  \\
  &2G_{\frac{i-1}{2} - 1} + \frac{i-1}{2} &&= \frac{i^2-2i+1}{4},
  &\quad& \text{otherwise}.
  \end{alignedat}
\end{cases}
\end{equation}

\begin{equation}
R_i=
\begin{dcases}
2G_{\frac{i}{2} - 1} = \frac{i^2-2i}{4},                     & \text{if $2\mid i$}
\\
2G_{\frac{i-1}{2} - 1} + \frac{i-1}{2} = \frac{i^2-2i+1}{4}, & \text{otherwise}.
\end{dcases}
\end{equation}

\end{document}

enter image description here

For divisibility, it's better to use 2\mid i rather than 2|i. I'd use \text{even $i$} and \text{odd $i$} instead.

You must log in to answer this question.

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