3

I'm trying to write a good-looking optimization problem in LaTeX using amsmath. The MWE is this:

\documentclass[letter, 10pt, conference]{article} 

\usepackage{amsmath}

\begin{document}

\begin{align*}
    & \underset{x,u}{\text{minimize}} & & \frac{1}{2} \sum_{k=0}^{N-1} 
    \text{some looooooooooooooooooooooooong function of } x,u \\
    & \text{subject to} & &
    \begin{aligned}
        & \text{constraint 1}, & & k = 0,\ldots,N{-}1, \\
        & \text{constraint 2}, & & k = 0,\ldots,N{-}1\\
    \end{aligned}
\end{align*}

\end{document}

output of MWE

where I nested the aligned environment in the align environment, because I need the 'k= ...' to be horizontally aligned with each other and I don't want to introduce alignment characters in my objective function (the one after the summation sign).

The problem is this: the 'subject to' is not aligned with 'constraint 1', as it should. Is there a non-dirty way to fix this?

0

1 Answer 1

3

One could replace the aligned with a TABstack. The tabbing and EOL characters have been changed, when nested inside of an align environment.

OR you could just use the [t] option on the aligned.

\documentclass[letter, 10pt, conference]{article} 

\usepackage{amsmath,tabstackengine}
\stackMath
\setstackTAB{\&}
\setstackEOL{\#}
\begin{document}

\begin{align*}
& \underset{x,u}{\text{minimize}} & & \frac{1}{2} \sum_{k=0}^{N-1} 
\text{some looooooooooooooooooooooooong function of } x,u \\
& \text{subject to} & &
\alignLongunderstack{%
\& \text{constraint 1}, \& \& k = 0,\ldots,N{-}1, \#
\& \text{constraint 2}, \& \& k = 0,\ldots,N{-}1
}
\end{align*}
\end{document}

enter image description here

Here is using the [t] option on the aligned to get the same thing:

\documentclass[letter, 10pt, conference]{article} 

\usepackage{amsmath}
\begin{document}

\begin{align*}
    & \underset{x,u}{\text{minimize}} & & \frac{1}{2} \sum_{k=0}^{N-1} 
    \text{some looooooooooooooooooooooooong function of } x,u \\
    & \text{subject to} & &
    \begin{aligned}[t]
        & \text{constraint 1}, & & k = 0,\ldots,N{-}1, \\
        & \text{constraint 2}, & & k = 0,\ldots,N{-}1\\
    \end{aligned}
\end{align*}

\end{document}

enter image description here

2
  • I went with your second suggestion because it's the closest to what I had, thx!
    – Nibor
    Feb 18, 2015 at 15:57
  • @Nibor I agree completely. Feb 18, 2015 at 15:58

You must log in to answer this question.

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