3

How can i use multiple alignment inside cases environment? i tired to use alignat, align* ... but it seems that they dont work inside equation environment.

\begin{equation}
\label{eq:13}
\begin{aligned}
W_{ij} = \begin{cases}
tf_{ij} \times \log \left( \frac{N}{n_i} \right) &if\quad &AW_i = 0\\
AW_i \times tf_{ij} \times \log \left( N/ n_i \right) &if\quad 0<&AW_i<1\\
\left(1 + \log \left( AW_i \right) \right) \times tf_{ij} \times \log 
\left(\frac{N}{n_i} \right) &if\quad &AW_i \geq 1
\end{cases}
\end{aligned}
\end{equation}

when i insert second & for each case it returns error !

0

2 Answers 2

4

Basically, use only one & symbol per row. If this were my document, I'd stick with the default layout for the right-hand column of the cases environment, which is left alignment of the material. For sure, you can't used an aligned environment to achieve your formatting objective.

Two additional comments: (i) Use \left and \right only sparingly. (ii) Try to keep your notation consistent. At times, you use \frac{N}{n_i}, while at others you write N/n_i. In the present context, I'd use the latter, i.e., inline-fraction notation.

enter image description here

Note also that I changed all instances of tf_{ij} in your code to \mathit{tf}_{\!ij}, both to tighten up the appearance of tf and to "snug up" the subscript term to its base. If you have a lot of instances of tf_{ij}, you may want to create a shorthand macro, say, \newcommand\tfij{\mathit{tf}_{\!ij}}, and then replace all instances of tf_{ij} in your document with \tfij.

\documentclass{article}
\usepackage{amsmath} % for 'cases' env. and '\text' macro
\begin{document}
\begin{equation}
\label{eq:13}
W_{ij} = 
\begin{cases}
  \mathit{tf}_{\!ij} \times \log(N/n_i) 
     & \text{if $AW_i = 0$}\\
  AW_i \times \mathit{tf}_{\!ij} \times \log(N/n_i) 
     & \text{if $0<AW_i<1$}\\
  (1 + \log AW_i) \times \mathit{tf}_{\!ij} \times \log(N/n_i) 
     & \text{if $AW_i \geq 1$}
\end{cases}
\end{equation}
\end{document}

Addendum: For the case at hand (pun intended), what you may want to think about, in terms of changing the layout, is to right-align the material in the first column of the cases environment.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for 'cases' env. and '\text' macro
\newcommand\tfij{\mathit{tf}_{\!ij}}
\begin{document}

\begin{equation}
\label{eq:13a}
W_{ij} = 
\begin{cases}
  \hfill \tfij \times \log(N/n_i) 
     & \text{if $AW_i = 0$}\\
  \hfill AW_i \times \tfij \times \log(N/n_i) 
     & \text{if $0<AW_i<1$}\\
  (1 + \log AW_i) \times \tfij \times \log(N/n_i) 
     & \text{if $AW_i \geq 1$}
\end{cases}
\end{equation}
\end{document}

Second addendum, to address the OP's follow-up comment: To achieve the desired special alignment of the material in the second column of the cases environment, I suggest you use \phantom statements in rows 1 and 3.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for 'cases' env. and '\text' macro
\newcommand\tfij{\mathit{tf}_{\!ij}}
\begin{document}

\begin{equation}
\label{eq:13aa}
W_{ij} = 
\begin{cases}
  \hfill \tfij \times \log(N/n_i) 
     & \text{if $\phantom{0<{}}AW_i = 0$}\\
  \hfill AW_i \times \tfij \times \log(N/n_i) 
     & \text{if $0<AW_i<1$}\\
  (1 + \log AW_i) \times \tfij \times \log(N/n_i) 
     & \text{if $\phantom{0<{}}AW_i \geq 1$}
\end{cases}
\end{equation}
\end{document}
2
  • Thanks alot for your comments. But i would like to have two alignments symbol for each case. One before "if" and another one before "AW".
    – DAkbariSE
    Apr 28, 2018 at 7:15
  • @danitiger33 - I've posted an addendum to show how your specific alignment needs might be met. Incidentally, IMNSHO, $0=AW_i$ would look better than $\phantom{0<{}}AW_i = 0$.
    – Mico
    Apr 28, 2018 at 7:24
3

Since the cases environment as defined by amsmath is basically just

\left\lbrace
\array{@{}l@{\quad}l@{}}%
...
\endarray \right.

it is no great task to use an explicit array environment with whatever columns and alignment you want.

\begin{equation}
\label{eq:13}
W_{ij} = \left\lbrace\,
\begin{array}{@{}r@{\quad}l@{}l@{}}
tf_{ij} \times \log (N/n_i) &\text{if}\quad &AW_i = 0\\
AW_i \times tf_{ij} \times \log (N/n_i) &\text{if}\quad 0<{}&AW_i<1\\
\bigl(1 + \log(AW_i) \bigr) \times tf_{ij} \times \log 
(N/n_i) &\text{if}\quad &AW_i \geq 1
\end{array}
\right.
\end{equation}

Note the 0<{}& to get the binary-relation spacing correct. I used right-alignment as per @Mico's suggestion, but assumed tf and AW are products, not single variables.

You must log in to answer this question.

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