3

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

  • 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. – jub0bs 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
4

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}

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.