6

How to get this format? I want to get this strictly.enter image description here

Thanks for the answer in advance. Here it is my code

\begin{alignat*}{9}
 \hspace{30 mm}\text{maximize }   & \sum_{i=1}^N d_i U_i                  \\               
 \text{s.t.}\quad&&l_{ij}&{}+{}r_{ij}{}+{}u_{ij}{}+{}o_{ij}  &\;\geqslant\;&s_{i}{}+{}s_{j}{}-{}1\\ 
 & &x_i&{}-{}x_j{}+{}Wl_{ij}\;\leqslant &\;&W{}-{}w_{i} \\
 &&&x_j{}-{}& x_i&{}+{}&W&r_{ij}&\;\leqslant &\;&W&{}-{}&w_{j} \\
 &&y_i&{}-{}& y_j&{}+{}&H&u_{ij}&\;\leqslant &\;&H&{}-{}&h_{i} \\
 &&y_j&{}-{}& y_i&{}+{}&H&o_{ij} &\;\leqslant &\;&H&{}-{}&h_{j} \\
 %& \rlap{$x_j \geqslant 0,\; j=1,2,3.$}\\
&&0\leqslant x_i\leqslant &W{}-{}w_i &  \\
&&0\leqslant y_i\leqslant &H{}-{}h_i &  \\

 & \displaystyle &l_{ij},&r_{ij},&u_{ij},&o_{ij}&\;\in&\; &\{0,1\}\\
& \displaystyle &s_{i}&&\;\in&\; &\{0,1\}
 \end{alignat*}
Torbjørn T.
  • 206,688

3 Answers3

5

Something like this? Note that you don't really need alignat (and you're giving too many equation columns to that environment).

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align*}
  \max\quad        & \sum_{i=1}^n p_i s_i                                                          \\
  \text{s.t.\quad} & \ell_{ij}+r_{ij}+u_{ij}+o_{ij}+b_{ij}+f_{ij}\ge s_i+s_j-1 &   & i,j=1,\dots,n \\
                   & x_i-x_j+W\ell_{ij}\le W-w_i                               &   & i,j=1,\dots,n \\
                   & 0\le x_i\le W-w_i                                         &   & i=1,\dots,n   \\
                   & s_i\in\{0,1\}                                             &   & i=1,\dots,n   \\
                   & x_i,y_i,z_i\ge0                                           &   & i=1,\dots,n   
\end{align*}
\end{document}

enter image description here

Take a look at this question: What does a double ampersand (&&) mean in LaTeX? to see how alignment works inside the align environment.

Herr K.
  • 17,946
  • 4
  • 61
  • 118
4

Similar to Herr K. but more “semantic”

\documentclass{scrartcl}
\usepackage{mathtools,array,amssymb}

\let\geq\geqslant
\let\leq\leqslant

\def\maximize#1\subjectto#2\stop{%
  \begin{array}{r>{\displaystyle}l}
    \text{max.} & #1 \\
    \text{s.t.} & \begin{array}[t]{@{}>{\displaystyle}l@{\qquad}>{\displaystyle}l@{}}#2\end{array}
  \end{array}%
}

\begin{document}

\[
  \maximize \sum_{i=1}^n p_i s_i
  \subjectto
    \ell_{ij} + r_{ij} + u_{ij} + o_{ij} + b_{ij} + f_{ij} \geq s_i + s_j - 1 & i, j = 1, \dots, n \\
    x_i - x_j + W\ell_{ij} \leq W - w_i                                       & i, j = 1, \dots, n \\
    0 \leq x_i \leq W - w_i                                                   & i = 1, \dots, n \\
    s_i \in \{0,1\}                                                           & i = 1, \dots, n \\
    x_i, y_i, z_i \geq 0                                                      & i = 1, \dots, n \\ 
  \stop
\]

\end{document}

enter image description here

Manuel
  • 27,118
4

There's no need for the \displaystyle directives, no need to surround - and + with {} (empty math atoms), and no need for the \; spacing directives. Instead, use a single align* environment. To maximize the likeness with the template, use \ell instead of l, load a Times Roman font family and (not implemented in the code shown below) use \leq and \geq instead of \leqslant and \geqslant.

enter image description here

\documentclass{article}    
\usepackage{amsmath,amssymb,newtxtext,newtxmath}
\begin{document}
\begin{align*}
\max\qquad&\sum_{i=1} p_i s_i \\               
\text{s.t.}\qquad 
&\ell_{ij}+r_{ij}+u_{ij}+o_{ij} +b_{ij}+f_{ij}\geqslant s_i+s_j-1 &&i,j=1,\dots,n\\ 
&x_i-x_j+W\ell_{ij} \leqslant W-w_i &&i,j=1,\dots,n\\
&x_j-x_i+Wr_{ij} \leqslant W-w_j &&i,j=1,\dots,n\\
&y_i-y_j+Hu_{ij} \leqslant H-h_i &&i,j=1,\dots,n\\
&y_j-y_i+Ho_{ij} \leqslant H-h_j &&i,j=1,\dots,n\\
&z_i-z_j+Db_{ij} \leqslant D-d_i &&i,j=1,\dots,n\\
&z_j-z_i+Df_{ij} \leqslant D-d_j &&i,j=1,\dots,n\\
&0\leqslant x_i  \leqslant W-w_i &&i=1,\dots,n\\
&0\leqslant y_i  \leqslant H-h_i &&i=1,\dots,n\\
&0\leqslant z_i  \leqslant D-d_i &&i=1,\dots,n\\
&\ell_{ij},r_{ij},u_{ij},o_{ij},b_{ij},f_{ij}\in\{0,1\} &&i,j=1,\dots,n\\
&s_i\in\{0,1\}           &&i=1,\dots,n\\
&x_i,y_i,z_i \geqslant 0 &&i,j=1,\dots,n
\end{align*}
\end{document}
Mico
  • 506,678