3

I'm trying to create a nicely looking optimization problem in LaTeX using amsmath. Here is a MWE:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{subequations}
\begin{alignat}{2}
    \text{maximize} \quad & \rlap{some looooooooooooooong objective function of $x,u$ } \\
    \text{with} \quad & \text{constraint 1} \quad & k=0,\ldots N{-}1 \\
    & \text{constraint 2} & k=0,\ldots N{-}1
\end{alignat}
\end{subequations}
\end{document}

Output of MWE

I need the \rlap because the 'k=0...' needs to be vertically aligned and I don't want to introduce alignment characters in my objective function.

As you can see, the equation number 1a overlaps the formula in the first line. Is there a clean way to prevent this?

2
  • Maybe this is a naive question but if yout first line doesn't contain any formula as in your example, why would you number it? If it contains a formula, it's up to you to break it with, say, the multlined environment. – Bernard Feb 18 '15 at 17:18
  • You're hiding the looooong formula from TeX's computations, so it can't know it's overlong. – egreg Feb 18 '15 at 17:56
1

I believe this is a solution independent of whether the two constraints have equal size:

\begin{subequations}
\begin{alignat}{3}
    \text{maximize} \quad & \text{some looooooo}&&\text{oooooooong objective function of $x,u$} \\
    \text{with} \quad & \text{constraint 1} && k=0,\ldots N{-}1 \\
    & \text{constraint 2} && k=0,\ldots N{-}1
\end{alignat}
\end{subequations}

with an output:

output

0

Here is another option without using \rlap, which works as long as the length of constraint 1 is the same than constraint 2.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{subequations}
  \begin{alignat}{2}
    \text{maximize} \quad & \text{some looooooooooooooong objective function of $x,u$} \\
    \text{with} \quad & \text{constraint 1} \quad k=0,\ldots N{-}1 \\
    & \text{constraint 2} \quad k=0,\ldots N{-}1
  \end{alignat}
\end{subequations}

\end{document}

And the output looks like this:

final output

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.