[Tex/LaTex] How to align equations

alignequationsmath-mode

I am trying to write a set of equations similar to some found in a book I am reading. Below is how the book has formatted the equations:

book equations

and here is what I have so far:

my equations

How can I align my equations so that "maximize" and "subject to" are aligned, while also aligning the sums? I do not want to display "(KP)" or any equation numbers on the side.

Here is the code I wrote:

\begin{equation*}
\begin{aligned}
    \text{maximize} \sum_{j=1}^{n}p_j x_j \\
    \text{subject to} \sum_{j=1}^{n}w_j x_j \leq c, \\
    x_j \in \{0,1\}, j = 1, \ldots, n.
\end{aligned}
\end{equation*}

Best Answer

output

Use the align environments from amsmath:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align}
  \text{maximize} &\null \sum_{j=1}^n p_j x_j \\
  \text{subject to} &\null \sum_{j=1}^n w_j x_j \leq c, \\
  &\null x_j \in \{0, 1\}, \quad j=1,\dots,n.
\end{align}
\end{document}
Related Question