# Latex subequations with “align” does not align?

Why does the second element on each line not align vertically? (z and x{im} in this case)

 \begin{subequations}
\label{eq:optim2}
\begin{align}
& \text{minimize}   & z       &= \sum_{i} c_m &                   &     &                      \label{eq:cost}\\
& \text{subject to} & x_{im}  &\leq 0 \,,     & \forall &  m, i \;&| \; & p_{ij}   = 1          \label{eq:const1}
\end{align}
\end{subequations}


## migrated from stackoverflow.comNov 20 '13 at 2:11

This question came from our site for professional and enthusiast programmers.

• Do you by any change mean horizontal alignment? Vertically the second elements are on the height of their respective line. And if, what’s wrong with the alignment? Looks good to me (though I wouldn’t use that many alignment points). – Qrrbrbirlbel Nov 20 '13 at 2:44

This is one of thos cases where I think alignment at the relations (the = and the \le) is incorrect. It suggests a parallel between the two lines that is not really present. I would align everything to the left, and use alignat to avoid excessive space. Remember that both align and alignat alternate beween right and left alignment. Also note that I am putting the \forall clause in the same cell with the inequality because it is no really a separate condition. So here are two possibilities. In the first, alignment is at the left. In the second, alignment is at the first relation:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{subequations}
\begin{alignat}{2}
& \text{minimize}\quad   && z = \sum_{i} c_m  \\
& \text{subject to}\quad && x_{im} \leq 0 \,,\ \forall m, i \mid p_{ij} = 1
\end{alignat}
\end{subequations}
\begin{subequations}
\begin{alignat}{2}
& \text{minimize}\quad   &      z &= \sum_{i} c_m  \\
& \text{subject to}\quad & x_{im} &\leq 0 \,,\ \forall m, i \mid p_{ij} = 1
\end{alignat}
\end{subequations}
\end{document}


I used \mid instead of \;|\; because it supplies its own spacing.