Math & ScienceVertical alignment in array environment

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
chen
Posts: 3
Joined: Sun Jan 24, 2010 3:25 pm

Vertical alignment in array environment

Post by chen »

Hi, I've got a nested array that outputs:
2me74o2.jpg
2me74o2.jpg (22.46 KiB) Viewed 16275 times
with code:

Code: Select all

$$\begin{array}[t]{ll}
\min &x_1 - x_2 \\
\textup{s.t.} &\begin{array}{lclll}
         5y_1 & \leq & x_1 & \leq & 12y_1+2\\
         y_2  & \leq & x_2 & \leq & 9(1-y_2) + 1\\
         3y_3  & \leq & x_2 & \leq & 7(1-y_3) + 3\\
         5y_4  & \leq & x_2 & \leq & 5(1-y_4) + 5\\
         10y_5 & \leq & x_2 & \leq & 10\\
        \end{array}\\
        &x_1, x_2 \geq 0\\
        &x_2 \in \ZZ\\
\end{array}$$
but I would like it to look like:
25zqtrd.jpg
25zqtrd.jpg (22.38 KiB) Viewed 16275 times
I've been tearing my hair out all day - I've been trying to look up stuff like vertical alignment with the array environment but just got absolutely nowhere.

Thanks very much.


Edit by localghost: Preferably no external links (see Board Rules). Attachments go onto the forum server where possible.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Vertical alignment in array environment

Post by Stefan Kottwitz »

Hi Chen,

you already used the optional positional argument t. Do it again for the array inside:

Code: Select all

\textup{s.t.} &\begin{array}[t]{lclll}
This way s.t. would align with the top of the array like desired.

Btw. I would prefer an aligned or align environment instead of array, further \[ ... \] instead of $$...$$.

Stefan
LaTeX.org admin
chen
Posts: 3
Joined: Sun Jan 24, 2010 3:25 pm

Re: Vertical alignment in array environment

Post by chen »

Thanks - but also, how can I remove the left padding the nested array so that the 5y_1 on the second line and so on lines up with x_1 on the first line? And how can I reduce the gap between the <=s? Thanks.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Vertical alignment in array environment

Post by Stefan Kottwitz »

chen wrote:how can I remove the left padding the nested array so that the 5y_1 on the second line and so on lines up with x_1 on the first line?
Insert @{}:

Code: Select all

\textup{s.t.} &\begin{array}[t]{@{}lclll}
chen wrote:And how can I reduce the gap between the <=s? Thanks.
User further @{}:

Code: Select all

\textup{s.t.} &\begin{array}[t]{@{}l@{}c@{}l@{}l@{}l}
No space is a bit extreme ... so you might use something like @{\,} or @{\hspace{...}} instead.

Stefan
LaTeX.org admin
Post Reply