Generalarray justification

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

array justification

Post by CoolnessItself »

I'm trying to imitate a book I'm reading for spacing when formulating LP problems.
Try this guy:

Code: Select all

\[ \begin{array}{rlr}
    \mbox{minimize}  & \sum c_{ij}x_{ij} \\
    \mbox{subject to} & \sum\limits_{j=1}^{n}x_{ij} - \sum\limits_{k=1}^{n}x_{ki}   & i=1,2,...,n\\
                & x_{ij} \ge 0 &  i,j=1,2,...,n.
    \end{array}
\]
The two problems I can't figure out how to fix:
1) The n from the constraints (above summation in second line) looks like its supposed to be the index for the top-line summation, so line spacing between equations needs to be increased ... how?
2) Can the columns of the array be spaced out more, so that "minimize" is spaced farther left from the equations, and the listing of $i=1...n" is farther right? I think the right column especially should be spaced farther away from the text and equations. Greater spacing between columns would also be helpful.

Any ideas?

Recommended reading 2024:

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

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

php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

array justification

Post by php1ic »

You can alter the line spacing with \arraystretch, and for the columns I would suggest simply adding two more columns with nothing in them, as below.

Code: Select all

\renewcommand\arraystretch{2}
\[ \begin{array}{rclcr}

    \mbox{minimize}   && \sum c_{ij}x_{ij} \\
    \mbox{subject to} && \sum\limits_{j=1}^{n}x_{ij} - \sum\limits_{k=1}^{n}x_{ki}   && i=1,2,...,n\\
                      && x_{ij} \ge 0 && i,j=1,2,...,n.
    \end{array}
\]
If you only want to change the line spacing for this one set of equations, you can set it back to the default with \renewcommand\arraystretch{1}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

array justification

Post by localghost »

It seems better to use amsmath and an environment provided by this package,

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage{amsmath}

\begin{document}
  \begin{alignat*}{2}
    \text{minimize}\qquad & \sum c_{ij}x_{ij} \\
    \text{subject to}\qquad & \sum_{j=1}^{n}x_{ij}-\sum_{k=1}^{n}x_{ki}\qquad & i &= 1,2,\ldots,n \\
    & x_{ij} \ge 0 & i,j &= 1,2,\ldots,n.
  \end{alignat*}
\end{document}
The package manual tells you more.


Best regards
Thorsten
Post Reply