# Multiple alignemnt tabs within cases/equation environment

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

$$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}$$


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 &

$$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}$$


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

## 1 Answer

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}

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}

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}

$$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{document}


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.