TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to typeset a multiple line optimization problem in LaTeX.

I have had a lot of difficulty using the align and alignat environments to get things to align properly.

I recently managed to find a solution that can get proper alignment by using an array environment inside of an align environment. A sample of this code looks like

    \min_{\bm{\alpha},\bm{\beta},\bm{\gamma},\lambdab} & \frac{1}{N}\sum_{i=1}^{N}\alpha_i + C_0\sum_{j=1}^{P}\beta_j + C_1\sum_{j=1}^{P}{\gamma_j} & \\
    \textrm{s.t.} & & \\
    & -M\alpha_i + \varepsilon \leq y_i \mathbf{x}_i^T \lambdab \leq M(1-\alpha_i) + \varepsilon & i= 1\ldots N \\
    & -M\alpha_i + \varepsilon \leq y_i \mathbf{x}_i^T \lambdab \leq M(1-\alpha_i) + \varepsilon & i= 1\ldots N 

My issue here is that I cannot number each of the rows inside the array environment. I am wondering if anyone knows a way to number / label these rows?

I realize that there have been several solutions that have been posted here, but in many cases the fix seems involve defining my own numbering system within the equations. I would rather try to avoid this since I am using numbering throughout the remainder of the paper, and I think that this would produce a conflict (I could be wrong).

If not, I would be happy with any solution that can generically produce this type of alignment (i.e. 3 columns, 1 left centered; 1 middle centered; 1 left centered).

share|improve this question
Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. – Jubobs Nov 7 '13 at 19:05
Done! Thanks for reminding me. I always think that someone just 'knows' the answer and may not necessarily have to tinker with the code itself. – Berk U. Nov 7 '13 at 20:38
up vote 3 down vote accepted

I would suggest you use alignat instead

Sample output




  &\min_{\bm{\alpha},\bm{\beta},\bm{\gamma},\lambda} \quad&&
  \frac{1}{N}\sum_{i=1}^{N}\alpha_i + C_0\sum_{j=1}^{P}\beta_j +
  C_1\sum_{j=1}^{P}{\gamma_j} \\ 
  &\textrm{s.t.} \notag \\
  &&& -M\alpha_i + \varepsilon \leq y_i \mathbf{x}_i^T \lambda \leq
  M(1-\alpha_i) + \varepsilon &\quad i&= 1\ldots N \\ 
  &&& -M\alpha_i + \varepsilon \leq y_i \mathbf{x}_i^T \lambda \leq
  M(1-\alpha_i) + \varepsilon & i&= 1\ldots N  


The alignment here is {rlrlrl}. An alternative much closer to your original coding is the equationarray environment from eqnarray. Here is an example, but I would prefer to stick to amsmath environments:

eqnarray sample




  \min_{\bm{\alpha},\bm{\beta},\bm{\gamma},\lambda} & \frac{1}{N}\sum_{i=1}^{N}\alpha_i + C_0\sum_{j=1}^{P}\beta_j + C_1\sum_{j=1}^{P}{\gamma_j} & \\
  \textrm{s.t.} & & \notag\\
  & -M\alpha_i + \varepsilon \leq y_i \mathbf{x}_i^T \lambda \leq
  M(1-\alpha_i) + \varepsilon & i= 1\ldots N \\ 
  & -M\alpha_i + \varepsilon \leq y_i \mathbf{x}_i^T \lambda \leq
  M(1-\alpha_i) + \varepsilon & i= 1\ldots N  

share|improve this answer
Thank you! The second solution was the one that I was looking for (the centering is important in many other examples). – Berk U. Nov 8 '13 at 20:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.