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.

I'm trying to align a set of constraints for a linear program formulation. The issue I'm having is that some of the summations are over two (or more) sets, while others are only over one. This makes it difficult to get the alignment to look good regardless of where I place the '&' align markers.

I'm currently using the align environment and the amsmath package.

Here's an MWE:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
subject to \\
\begin{align}
    & \displaystyle \sum_{j\in P, k\in K}y_{ijkw} = \sum_{a\in A}x_{aiw} && \forall i\in P, w\in S\\
    & \displaystyle \sum_{i\in P, k\in K}y_{ijkw} = \sum_{l\in P, k\in K}y_{jlkw} && \forall j\in P, w\in S\\
    & \displaystyle \sum_{i\in P, k\in K}y_{iukw} \geq U \\
    & \displaystyle \sum_{i\in P}x_{aiw} = area_{a} && \forall a\in A \\
    & \displaystyle \sum_{i\in P,  w\in S, k\in K}w_{ijkw}y_{ijkw} \geq 0.7Area_w && \forall j\in P\\
    \notag
\end{align}

\end{document}

Is there an environment, or something within align, I could use to make this look better?

enter image description here

share|improve this question
    
I'd like to include the rendered code in the question but I can't figure out how to do it. –  ABM Aug 13 '13 at 12:59
1  
You can make an image of the output and then upload using the image button in the editor, as you don't have the rep to include images directly, delete the ! from the generated markup, so it makes a link, and someone with edit rights will put the ! back. –  David Carlisle Aug 13 '13 at 13:07
    
I can see how to include an image from the internet, but not from my desktop. –  ABM Aug 13 '13 at 13:53
    
The image upload interface should have a "from web" or "from computer/browse" option (or in some browsers, eg chrome, you can drag and drop the image) –  David Carlisle Aug 13 '13 at 14:00

3 Answers 3

up vote 4 down vote accepted

Perhaps you might be interested in some of the overlapping functions provided by mathtools:

enter image description here

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/mathtools

\begin{document}
subject to
\begin{align}
    \sum_{\mathclap{j\in P, k\in K}} y_{ijkw} &= \sum_{a\in A}x_{aiw} && \forall i\in P, w\in S \\
    \sum_{\mathclap{i\in P, k\in K}} y_{ijkw} &= \sum_{\mathclap{l\in P, k\in K}}y_{jlkw} && \forall j\in P, w\in S \\
    \sum_{\mathclap{i\in P, k\in K}} y_{iukw} &\geq U \\
    \sum_{i\in P} x_{aiw} &= \text{area}_{a} && \forall a\in A \\
    \sum_{\mathclap{i\in P,  w\in S, k\in K}} w_{ijkw}y_{ijkw} &\geq 0.7\text{Area}_w && \forall j\in P
\end{align}

\end{document}

I don't particularly like the heavy overlaps (using \mathclap), but it showcases what can be achieved. Another option, instead of listing all the summation criteria in a single line, would be to use \substack, and list them underneath one another. Here's a small example showcasing what I mean only for the last equation:

enter image description here

  \sum_{\mathclap{\substack{i\in P,  w\in S \\ k\in K}}} w_{ijkw}y_{ijkw} &\geq 0.7\text{Area}_w && \forall j\in P
share|improve this answer
    
\smashoperator gives more flexibility –  daleif Aug 13 '13 at 14:12
    
@daleif can you provide an example? –  ABM Aug 13 '13 at 14:16
1  
@ABM: \smashoperator[<pos>]{<operator>} allows you to specify (through the optional [<pos>] argument) the overlap position. It's more flexible because you can easily change the code (overlap) rather than having to dig in the highest detail (the limit to your <operator> to change the overlap). For examples of its usage, see section 3.1.3 Smashing an operator (p 7) of the mathtools documentation. –  Werner Aug 13 '13 at 14:20

using \mathclap from mathtools (which automatically loads amsmath), and with a little manual spacing to restore the "natural" space at the right of the sums with wide limits, here's an approach that gives a more even result:

\documentclass{article}
\usepackage{mathtools}

\begin{document}
subject to
\begin{align*}
    & \sum_{\mathclap{j\in P, k\in K}} \quad y_{ijkw}
       = \sum_{a\in A}x_{aiw} && \forall i\in P, w\in S\\
    & \sum_{\mathclap{i\in P, k\in K}} \quad y_{ijkw}
       = \sum_{l\in P, k\in K}y_{jlkw} && \forall j\in P, w\in S\\
    & \sum_{\mathclap{i\in P, k\in K}} \quad y_{iukw} \geq U \\
    & \sum_{i\in P}x_{aiw} = area_{a} && \forall a\in A \\
    & \sum_{\mathclap{i\in P,  w\in S, k\in K}} \hspace{1.75em} w_{ijkw}y_{ijkw}
      \geq 0.7Area_w && \forall j\in P
\end{align*}
\end{document}

it wasn't clear to me that you wanted the lines numbered, so i used the starred form of align; just remove it if you do want numbers. the way you used \notag has no effect as it's on a line by itself.

also, the double backslash after "subject to" isn't needed to shift into display math mode, and indeed it adds extra space that generally isn't wanted.

output of example code

share|improve this answer
    
When I don't place \notag on the line before \end{align} I get a blank line numbered (6) in my rendered document. –  ABM Aug 13 '13 at 14:00
1  
@ABM: Drop the ending \\ as well as the \notag. You don't need to (shouldn't) end the last line with \\. –  Werner Aug 13 '13 at 14:14

Werner's answer gave me an idea that makes the alignment much cleaner.

I use \phantom with \substack to insert a line of blank space equivalent to the length of two sets under any summations that are over a single set. I've placed \phantoms underneath all the summations to keep the spacing consistent.

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

\begin{document}
subject to \\
\begin{align}
& \displaystyle \sum_{\mathclap{\substack{i\in P, k\in K\\ \phantom{i\in P}}}}y_{ijkw} = \sum_{a\in A}x_{aiw} && \forall i\in P, w\in S\\
    & \displaystyle \sum_{\mathclap{\substack{i\in P, k\in K\\ \phantom{i\in P}}}}y_{ijkw} = \sum_{\mathclap{\substack{l\in P, k\in K\\ \phantom{i\in P}}}}y_{jlkw} && \forall j\in P, w\in S\\
    & \displaystyle \sum_{\mathclap{\substack{i\in P, k\in K\\ \phantom{i\in P}}}}y_{iukw} \geq U \\
    & \displaystyle \sum_{\mathclap{\substack{i\in P \\ \phantom{i\in P}\phantom{i\in P}}}}x_{aiw} = area_{a} && \forall a\in A \\
    & \displaystyle \sum_{\mathclap{\substack{i\in P,  w\in S, \\ k\in K}}}w_{ijkw}y_{ijkw} \geq 0.7Area_w && \forall j\in P\\
\notag
\end{align}
\end{document}

Rendered Code

share|improve this answer
1  
Note you don't need \displaystyle AMS alignments are display by default –  David Carlisle Aug 13 '13 at 14:01

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.