Formatting linear programs

To get the wider spacing associated with display-style math, you could use a combination of the gather* and aligned environments (both provided by the amsmath package):

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{gather*}
\max_{x,y}\quad 300x + 100y \\
\begin{aligned}
\textup{s.t.}\quad 6x + 3y  &\leq  40\\
                   x - 3y  &\leq  0 \\
         x + \tfrac{1}{4}y  &\leq  4 \\
\end{aligned}
\end{gather*}
\end{document}

Using the array environment, you can do as follows:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{equation*}
\setlength\arraycolsep{1.5pt}
  \begin{array}{l@{\quad} r c r c r}
    \max          & 300x & + &         100y &      &    \\
    \mathrm{s.t.} &   6x & + &           3y & \geq & 40 \\
                  &    x & - &           3y & \geq &  0 \\
                  &    x & + & \frac{1}{4}y & \geq &  4
  \end{array}
\end{equation*}

\end{document}

output

This gives a proper alignment IMHO.


The gather environment is working well in this example only because the objective function and the constraints have similar sizes.

If you don't need to align the objective function with your constraints, you can nest an array in an align environment:

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools,amssymb}

\begin{document}

\begin{align*}
    &\mathrm{max} \quad 300x + 100y  \\[2pt] % if you need space between objectif and constraints
    &\mathrm{s.t.} \quad 
    \begin{array}[t]{r c r c r}
         6x & + &           3y & \geq & 40 \\
          x & - &           3y & \geq &  0 \\
          x & + & \frac{1}{4}y & \geq &  4
     \end{array}
\end{align*}

\end{document}

enter image description here

I have noticed that the \max command does not align very well in the align environment, I have replaced it by \mathrm{max}.

Tags:

Math Mode