7

The following MWE shows the following bogus optimization problem with objective and constraints. I'm trying to achieve a visual alignment of the contraints in lines 2 and 3. However, a simple \phantom with the \sum_{...} as an argument does not create an equal space. I tried out adding {} left and right, but that did not seem to do be the solution, either. So the question is this:

How can I align the constraints on their operators?
(Btw: if there is a way to just use the & facilities from align directly to achieve this, I would be glad to see that as a solution. I do not see how.)

Image

constraints misaligned despite phantom

M-not-WE

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\min_{x,y}\ & c_1 x_1 + c_2 x_2 + c_3 y \\
\mathrm{s.t.}\, & 
  \sum_{i\in \{1,2\}} x_i \geq d \\
& \phantom{\sum_{i\in \{1,2\}}} % what to add here?
               x_i \leq y \ \forall i\in\{1, 2\}
\end{align*}
\end{document}
9

Use an aligned environment:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\min_{x,y}\ & c_1 x_1 + c_2 x_2 + c_3 y \\
\mathrm{s.t.}  & \begin{aligned}[t]
                   \sum_{i\in \{1,2\}} x_i & \geq d \\
                   x_i                     &\leq y \ \forall i\in\{1, 2\}
                 \end{aligned}
\end{align*}
\end{document}

enter image description here

1

Here is an approach using stacking a TABstack under the top line.

\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\begin{document}
\[
\setstackgap{S}{5pt}
\def\stackalignment{l}
\stackunder{\displaystyle\min_{x,y}\ c_1 x_1 + c_2 x_2 + c_3 y}{%
\alignShortstack{%
\,\mathrm{s.t.}\,  \displaystyle\sum_{i\in \{1,2\}} x_i \geq& d \\
x_i \leq& y \ \forall i\in\{1, 2\}
}}
\]
\end{document}

enter image description here

1

If you want to use \phantom, you can do it as follows:

\begin{align*}
\min_{x,y}\ & c_1 x_1 + c_2 x_2 + c_3 y \\
\mathrm{s.t.}\, & 
  \sum_{i\in \{1,2\}} x_i \geq d \\
& \phantom{{}\sum_{i\in \{1,2\}}{}} % what to add here?
               x_i \leq y \ \forall i\in\{1, 2\}
\end{align*}

The reason is that there is some space around the sum that separates the sum from its neighbours. If the \sum has no direct neighbours, since it is "alone" within its \phantom group, then this space disappears. If you add empty pairs of braces before and after the sum, the space is reinserted.

1

I propose a small improvement to @Harish Kumar's solution, using mathtools, and two variants for the layout of this equation:

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{align*}
                                     & \min_{x,y}\{ c_1 x_1 + c_2 x_2 + c_3 y\} \\
                                     & \,\mathrm{s. t.}\enspace \begin{aligned}[t]
  \sum_{\mathclap{i\in \{1,2\}}} x_i & \geq d \\
  x_i & \leq y \ \forall i\in\{1, 2\}
  \end{aligned}
\end{align*}

\begin{align*}
            & \min_{x,y}\{ c_1 x_1 + c_2 x_2 + c_3 y\} \\
            & \,\mathrm{s. t.}\enspace \begin{aligned}[t]
  x_1 + x_2 & \geq d \\
  x_1,x_2 & \leq y
  \end{aligned}
\end{align*}

\begin{align*}
    & \min_{x,y}\{ c_1 x_1 + c_2 x_2 + c_3 y\} \\
    & \,\mathrm{s. t.}\enspace \begin{array}[t]{|l}
  x_1 + x_2 \geq d \\
  x_1,x_2\leq y
  \end{array}
\end{align*}
\end{document}

enter image description here

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.