Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When stating LP problems I usually use something along the following

\begin{tabular}{ l c p{1pt} c }
max     & \multicolumn{3}{l}{$300x + 100y$} \\
s.t.    & $6x + 3y$ & $\leq$ & $40$\\
        & $x - 3y$  & $\leq$ & $0$ \\
        & $x + \frac{1}{4}y$ & $\leq$ & $4$ \\
\end{tabular}

But this forces the use of inline math, and require me to adjust column width manually (and it's still not perfect since the spacing between the right hand side and left hand side of \leq is wrong).

What I really would like was a solution that allowed for display math, with correct spacing and no need for manual formatting with p{}.

How would I write a version that fixes this?

share|improve this question
1  
Something like an array environment would probably suffice here (see the first answer on this question; I don’t have time for a full answer right now). –  alexwlchan Feb 16 at 22:41
1  
A good thing is to read the fine document MathMode.pdf of Herbert Voß. –  Alain Matthes Feb 16 at 22:56
add comment

2 Answers 2

up vote 3 down vote accepted

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}
share|improve this answer
    
I love it! Even better than I could've imagined! –  Mathias Vorreiter Pedersen Feb 16 at 23:19
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.