0

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).

enter image description here

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

\begin{equation}
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}
\end{equation}

\begin{equation}
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{equation}


\end{document}
1
  • 1
    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

1 Answer 1

2

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: Result

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

6
  • 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.
    – Miyase
    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
  • 1
    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
  • 1
    @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.
    – Miyase
    Jun 5 at 23:45

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.