Take the 2-minute tour ×
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.

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

\documentclass{article}
\usepackage{amsmath,array}
\begin{document}
    \begin{align}
    \centering
    \begin{array}{>{\displaystyle}l>{\displaystyle}c>{\displaystyle\hspace{0.5cm}}l}
    \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 
    \end{array}
    \end{align}
\end{document}
\documentclass{article}

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
4  
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

1 Answer 1

up vote 3 down vote accepted

I would suggest you use alignat instead

Sample output

\documentclass{article}

\usepackage{amsmath,array,bm}

\begin{document}

\begin{alignat}{3}
  &\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  
\end{alignat}

\end{document}

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

\documentclass{article}

\usepackage{amsmath,array,eqnarray,bm}

\begin{document}

\begin{equationarray}{lc>{\hspace{0.5cm}}l}
  \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  
\end{equationarray}

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

 
discard

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.