# How can I align two cases (two automatically indexed equations)?

How can I align these cases? I also want to keep the equations indexed automatically.
I saw some previous topics on this but I wonder if it can be done without changing too much the code (not rewrite it completely).

\documentclass[journal]{IEEEtran}
\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{array}
\usepackage[caption=false,font=normalsize,labelfont=sf,textfont=sf]{subfig}
\usepackage{textcomp}
\usepackage{stfloats}
\usepackage{url}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{cite}
\hyphenation{op-tical net-works semi-conduc-tor IEEE-Xplore}
% updated with editoria
\usepackage{booktabs}

\begin{document}

$$x_{1, 2} = \begin{cases} m x_{n} & \text{if } p_{2}=1 \\ (1-m) x_{n} & \text{if } q_{2}=1 \\ 0 & \text{if } (p_{2}=0) \wedge (q_{2}=0) \end{cases}$$

$$x_{k} = \begin{cases} \frac{m }{1-m} x_{n}& \text{if } p_{3}\not=0 \\ \frac{(1-m)}{m}x_{n} & \text{if } q_{3}\not=0 \\ \end{cases}$$

\end{document}

• Instead of using two equation environments, combine them into a single align environment, placing an & just before the = sign in each, and placing \\  after the first \end{cases}. You may want to add a bit of vertical space there too, say by specifying \\[6pt] (or other appropriate amount, and no space before the opening bracket). Don't leave any blank lines. Jun 5 at 23:37

First, please keep in mind that subfig has been obsoleted for years and should no longer be used.

Back to your question, simply use the align environment:

\documentclass[journal]{IEEEtran}
\usepackage{amsmath}

\begin{document}

\begin{align}
x_{1, 2} &=
\begin{cases}
m x_{n} & \text{if } p_{2}=1 \\
(1-m) x_{n} & \text{if } q_{2}=1 \\
0  & \text{if } (p_{2}=0) \wedge (q_{2}=0)
\end{cases}\\
x_{k} &=
\begin{cases}
\frac{m }{1-m} x_{n}& \text{if } p_{3}\not=0 \\
\frac{(1-m)}{m}x_{n} & \text{if } q_{3}\not=0 \\
\end{cases}
\end{align}

\end{document}


which yields:

Also, you might consider using dcases instead of cases for better readibility, but it's a matter of taste.

• Thanks, how can I align "if"s as well?
– hana
Jun 5 at 23:35
• Not as far as I know, sorry. Unless I missed a feature, I'd do that with an array, and generate the equation numbers manually. Jun 5 at 23:37
• I see. You mentioned about subfig being obsoleted. What should I use to substitute it?
– hana
Jun 5 at 23:40
• To align the "if"s, you want to make the width of the left-hand side of the cases the same. Pick the longest LHS, then in the other cases, enter one line as \mathrlap{<expression to be printed>}\hphantom{$<long expression>$}. Requires mathtools. Jun 5 at 23:41
• @hana It's subcaption. A small tip: every once in a while, check CTAN. For example, the subfig page indicates that it's obsolete and points you to its replacement. In fact subfig has been obsoleted twice. Jun 5 at 23:45