4

I have a problem to align two blocks of equations within a split command. I would like the "subject to" in the following code, to be aligned to the left (where the miinimize function starts), but I also need the two constraint equations to be aligned with each other. This is the code I have so far:

\documentclass[review]{elsarticle}
\usepackage{siunitx} % Formats the units and values
\usepackage[fleqn]{amsmath}
\usepackage{xfrac}
\allowdisplaybreaks

\begin{document}
    \begin{align}
        \begin{split}
            \min_{u,v}\sum_{m=1}^{M} \bigg[ p_m \cdot \sum_{k=-N+1}^{0} \Big(
            &w_x \left\|  \hat{x}^k-x^{k,m}(u) \right\| + \Big. \bigg. \\
            &   \bigg. \Big. w_y\lVert \hat{y}^k-y^{k,m}(u,v) \rVert + 
            w_u\lVert u^k \rVert +  w_v\lVert v^k \rVert    \Big)   \bigg]
        \end{split}  \\
        \text{subject to:}\quad &u_L\leq u^k \leq u_U \\
        &u_L\leq u^k \leq u_U
    \end{align} 
\end{document}

Any suggestion?

mattdanzi
  • 330
Rodolfo
  • 55

2 Answers2

5

Here are two variants of a solution. I slightly improved your code, defining a \norm command, with adjustable delimiters, with the \DeclarePairedDelimiter command from mathtools.

\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter{\norm}\lVert\rVert

\begin{document}

\begin{align}
   & \min_{u,v}\sum_{m=1}^{M} \biggl[ p_m \cdot\smashoperator{\sum_{k=-N+1}^{0}}\:%
   \begin{aligned}[t]\Bigl(& w_x \norm[\big]{\hat{x}^k-x^{k,m}(u)} + w_y\norm[\big]{\hat{y}^k-y^{k,m}(u,v)} \\ %
  \mathllap{{} +{}} &w_u \norm[\big]{u^k} + w_v \norm[\big]{v^k}\Bigr) \biggr]
\end{aligned}
 \\
  & \text{subject to:}\quad u_L\leq u^k \leq u_U \\
  &\phantom{\text{subject to:}}\quad u_L\leq u^k \leq u_U
\end{align}

\begin{align}
   & \min_{u,v}\sum_{m=1}^{M} \biggl[ p_m \cdot\smashoperator{\sum_{k=-N+1}^{0}}\:%
   \begin{aligned}[t]\Bigl( w_x \norm[\big]{\hat{x}^k-x^{k,m}(u)} &+ w_y\norm[\big]{\hat{y}^k-y^{k,m}(u,v)} \\ %
   &+w_u \norm[\big]{u^k}+ w_v \norm[\big]{v^k}\Bigr) \biggr]
\end{aligned}
 \\
  & \text{subject to:}\quad u_L\leq u^k \leq u_U \\
  &\phantom{\text{subject to:}}\quad u_L\leq u^k \leq u_U
\end{align}

\end{document}

enter image description here

Bernard
  • 271,350
  • Thanks Bernard, this looks amazing! I never thought of using the \aligned command but it´s perfect. I like the second option you suggested better but both are exactly what I wanted. – Rodolfo Oct 23 '16 at 20:07
  • @Rodolfo: You'll note I replaced the pairs of \bigg( … \bigg) and the like with pairs of \biggl( … \biggr). This provides a better horizontal spacing around delimiters. – Bernard Oct 23 '16 at 20:26
  • great! also good to know this tip! I had to google them cause I didn´t know how to use them but seems to be much better way of writing equations in general (for anyone else interested check: [http://tex.stackexchange.com/questions/19480/why-use-the-control-sequences-bigl-biggl-bigr-or-biggr-as-i-can-always-us]). I also had to learned about the phantom, quite useful too. Thanks again! – Rodolfo Oct 23 '16 at 21:01
5

Here's a solution that uses a single align environment. As in @Bernard's answer, I load the mathtools package -- a superset of the amsmath package -- to set up a macro called \norm, using a \DeclarePairedDelimiter directive. The alignment points are the summation symbol in line 1 and the starts of the inequalities in lines 3 and 4.

enter image description here

\documentclass[review]{elsarticle}
\usepackage{siunitx} % Formats the units and values
\usepackage[fleqn]{mathtools} % automatically loads 'amsmath' too
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\begin{document}
\begin{align}
\min_{u,v}&\sum_{m=1}^{M} 
\biggl[ p_m \cdot \smashoperator[l]{\sum_{k=-N+1}^{0}} 
            \!\Bigl(w_x \norm[\big]{ \hat{x}^k-x^{k,m}(u) } \notag \\
          &\qquad\qquad+ w_y\norm[\big]{\hat{y}^k-y^{k,m}(u,v)} + 
           w_u\norm[\big]{ u^k} +  w_v\norm[\big]{v^k} \Bigr) \biggr]\\
\text{subject to:}\quad &u_L\leq u^k \leq u_U \\
                        &u_L\leq u^k \leq u_U
\end{align} 
\end{document}
Mico
  • 506,678
  • thanks for the answer Mico. Not exactly what I wanted though but @Bernard gave a great suggestion of using the \aligned inside my first equation and that solves it. That way there is also no need to use a \notag – Rodolfo Oct 23 '16 at 21:12