14

I really struggle to align a system of equation for an optimisation problem. It was all ok at the beginning until I started adding the constraint.

I've got this code so far:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{aligned}
\text{minimize}\qquad && \parallel A^{\text{ind}} w \text{ diag}(x^{\text{ind}})\parallel\\
\text{subject to }\qquad && w=b-s+w^0\\
\phantom{\text{subject to }} & l^b &\le b &\le u^b\\
\phantom{\text{subject to }} & l^s &\le s &\le u^s\\
\phantom{\text{subject to }} & l^{\text{bukd}} &\phantom{\le}  t(b+s) &\le u^t\\
\phantom{\text{subject to }} & l^{\text{bukd}} &\le A^{\text{dur}} w \text{ diag}(x^{\text{buk}}) &\le u^{\text{bukd}}\\
\phantom{\text{subject to }} & l^{\text{curp}} &\le A^{\text{dur}} w \text{ diag}(x^{\text{cur}}) &\le u^{\text{curp}}\\
\end{aligned}
\]
\end{document}

enter image description here

As you can see, the variable 'b' and 's' are not aligned in the middle. Moreover, the first less-or-equal signs are not aligned as well although they all have a symbol '&' before each of them.

Does anyone can help aligning, in the center, all the constraints of my optimisation problem?

4
  • Welcome to TeX.sx! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you.
    – jub0bs
    Apr 30 '13 at 15:03
  • 3
    The use of \parallel for denoting a norm is discouraged. Instead, use \lVert and \rVert.
    – jub0bs
    Apr 30 '13 at 15:11
  • What alignment are you exactly trying to achieve? Is the overall objective to effectively center all of the constraint statements?
    – oLas
    Apr 30 '13 at 15:13
  • I'm trying to align the first norm, with w=b-s+w, and b, and s etc... but I want a center aligment
    – Rio
    Apr 30 '13 at 15:24
7

Well, you can use the following for further improvements (you can remove \qquad, avoid \parallel etc.) but it will be progressively uglier;

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiter{\diagpars}{(}{)}
\newcommand{\diag}{\operatorname{diag}\diagpars}
\newcommand{\norm}[1]{\displaystyle \left\| #1 \right\|}

\begin{document}
\[
\begin{matrix}
\text{minimize} &&& \norm{A^{\text{ind}} w \diag{x^{\text{ind}}}}\\
\text{subject to } &&& w=b-s+w^0\\
& l^b             &\le &b                                             &\le &u^b\\
& l^s             &\le &s                                             &\le &u^s\\
& l^{\text{bukd}} &\le &t(b+s)                                        &\le &u^t\\
& l^{\text{bukd}} &\le &A^{\text{dur}} w \text{ diag}(x^{\text{buk}}) &\le &u^{\text{bukd}}\\
& l^{\text{curp}} &\le &A^{\text{dur}} w \text{ diag}(x^{\text{cur}}) &\le &u^{\text{curp}}\\
\end{matrix}
\]
\end{document}

enter image description here

Instead reformulate what your constraint is actually meaning for example b\in[l^b,u^b] etc.

2
  • 2
    i'd suggest using either \DeclareMathOperator{\diag}{diag} and then \diag for that string and similarly for the ones used as superscripts, or \mathrm for all of them, since, if this appears in an (italicized) theorem, they will all otherwise be set in italic. also, as a comment on the question suggested, \lVert and \rVert are much preferable to \parallel, which is defined as a relation, hence will have incorrect spacing. Apr 30 '13 at 15:36
  • @barbarabeeton There are many things to consider :) I've added a few more options.
    – percusse
    Apr 30 '13 at 15:40
11

The following may be close to what you're looking for:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\diag}{diag}
\begin{document}
\[
\text{Minimize\quad} 
\| A^{\text{ind}} w \diag(x^{\text{ind}}) \| 
\]
\[ 
\begin{array}{r @{}c@{} c @{}c@{} l}
\text{subject to:\quad}w&{}={}&\multicolumn{1}{@{}l}{b-s+w^0}\\
l^b &\le& b &{}\le{}& u^b\\
l^s &\le& s &\le& u^s\\
l^{\text{bukd}} &\le&  t(b+s) &\le& u^t\\
l^{\text{bukd}}  &\le& A^{\text{dur}} w \diag(x^{\text{buk}}) 
   &\le& u^{\text{bukd}}\\
l^{\text{curp}}  &\le& A^{\text{dur}} w \diag(x^{\text{cur}}) 
   &\le& u^{\text{curp}}\\
\end{array}
\]
\end{document}

The syntax governing the array environment may seem a bit dense at first, so here's a quick guide:

  • the two @{}c@{} constructs serve to position the equality/inequality symbols; the @{} directive suppresses the normal amount of intercolumn whitespace,
  • the r, c, and l directives serve to position the remaining material,
  • in the first row of the array, the {}={} stuff informs LaTeX that the = symbol should be treated as a relation operator (by inserting a bit of whitespace on either side); the same goes for the {}\le{} in the second row of the array. (Note that it's only necessary to specify the extra {} stuff once per column.)
  • In the first row of the array, the material on the RHS of the equality relation is forced flushleft via a \multicolumn{1}{@{}l}{...} statement. The @{} before the "l" is there to suppress LaTeX's default behavior of (re)inserting extra intercolumn whitespace in the amount of \arraycolsep.

Finally, I've placed the "minimize" and "subject to" groups into two separate displaymath environments. This inserts a bit more space and, should the need to do so arise, facilitates inserting a page break between the two groups.

3
  • I keep trying to find a reason not to like this because the array syntax is so opaque. But an array is the way to do it and the result is perfect.
    – Ryan Reich
    May 1 '13 at 0:06
  • @RyanReich - Thanks. I'll go ahead and provide some explanatory comments to make the syntax hopefully a bit less opaque. :-)
    – Mico
    May 1 '13 at 2:10
  • It's a great explanation, though you already had my vote.
    – Ryan Reich
    May 1 '13 at 2:31
6

A simple solution would simply be left aligning the constraints, by using a single alignment character:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{aligned}
\text{minimize}\qquad & \| A^{\text{ind}} w \text{ diag}(x^{\text{ind}})\|\\
\text{subject to }\qquad & w=b-s+w^0\\
& l^b \le b \le u^b\\
& l^s \le s \le u^s\\
& l^{\text{bukd}} \phantom{\le}  t(b+s) \le u^t\\
& l^{\text{bukd}} \le A^{\text{dur}} w \text{ diag}(x^{\text{buk}}) \le u^{\text{bukd}}\\
& l^{\text{curp}} \le A^{\text{dur}} w \text{ diag}(x^{\text{cur}}) \le u^{\text{curp}}\\
\end{aligned}
\]
\end{document}

Would then produce the following:

Output

4
  • 1
    Very clean, quite nicer
    – percusse
    Apr 30 '13 at 15:51
  • 2
    Are the \phantom{\text{subject to }} necessary? May 1 '13 at 1:36
  • 1
    Do replace \parallel with either \| or \Vert to avoid the extra bit of whitespace inserted by the former method.
    – Mico
    May 1 '13 at 2:25
  • @petergrill yes, good point. Updated and replaced \parallel
    – oLas
    May 1 '13 at 8:31
5

here's another possibility, although whether it's preferable to the one by percusse is a matter of personal taste.

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\diag}{diag}
\begin{document}
\begin{gather*}
\begin{split}
\llap{\text{minimize}\qquad\qquad} & \| A^{\mathrm{ind}} w \diag (x^{\mathrm{ind}})\| \\
\llap{\text{subject to}\qquad\qquad} & w=b-s+w^0
\end{split}\\
\begin{alignedat}{3}
  l^b &\le b &&\le u^b\\
  l^s &\le s &&\le u^s\\
  l^{\mathrm{bukd}} &\phantom{{}\le{}}  t(b+s) &&\le u^t\\
  l^{\mathrm{bukd}} &\le A^{\mathrm{dur}} w \diag(x^{\mathrm{buk}}) &&\le u^{\mathrm{bukd}}\\
  l^{\mathrm{curp}} &\le A^{\mathrm{dur}} w \diag(x^{\mathrm{cur}}) &&\le u^{\mathrm{curp}}
\end{alignedat}
\end{gather*}
\end{document}

output of example code

2
  • I think @Mico wins :) Though I would still write the inqualities as intervals to avoid such problems (or even put them into text as inline math).
    – percusse
    Apr 30 '13 at 15:46
  • @percusse -- i agree, and not just on time. mico's result looks nicer than mine. Apr 30 '13 at 17:12
5

Another possibility, with inequality signs vertically aligned, but keeping the cost and equality constraint to the left:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\diag}{diag}
\begin{document}
\begin{align*}
\text{minimize}   \quad & \lVert A^{\text{ind}} w \text{ diag}(x^{\text{ind}})\rVert \\
\text{subject to} \quad & w=b-s+w^0 \\
                        & \hspace{-.3em} % this is for correcting a small offset of the array to the right
\begin{array}{lcccl}
    l^b                 & \leq  & b                                           & \leq  & u^b             \\
    l^s                 & \leq  & s                                           & \leq  & u^s             \\
    l^{\text{bukd}}     & \leq  & t(b+s)                                      & \leq  & u^t             \\
    l^{\text{bukd}}     & \leq  & A^{\text{dur}} w \diag (x^{\text{buk}})     & \leq  & u^{\text{bukd}} \\
    l^{\text{curp}}     & \leq  & A^{\text{dur}} w \diag (x^{\text{cur}})     & \leq  & u^{\text{curp}} \\
\end{array}
\end{align*}
\end{document}
1
  • From all your suggestions, it looks like as it is not recommended to use the align editor to write down equation. Matrix and array look much more handy.
    – Rio
    Apr 30 '13 at 16:12

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.