2

I have an equation in an align environment that has a long line in it which is messing up the alignment of other lines because of the position of the &s (where the blue arrows are in the image below).

Here is a simplified example:

{\footnotesize
\begin{align}
    \text{minimise} \quad & \displaystyle\sum_{p \in \S{P}}\left(\displaystyle\sum_{(i,j) \in E \cap p} c_{ij}\right)z_{p},\\
    \text{subject to} \quad & \displaystyle\sum_{p \in \S{P}}\left(|V\cap p| - |E\cap p|\right)z_{p} = 1,\nonumber\\
        & \displaystyle\sum_{p \in \S{P}}\left(|(S\setminus\{l\}) \cap p| - |E(S)\cap p|\right)z_{p} \geq 0 & \forall\ l \in S \subseteq V,\nonumber\\
        & z_p \leq z_q & \forall  p,q\in \S{P},(i,j) \in E : p \ni (i,j),q \ni i,p \neq q\nonumber.
\end{align}
}

enter image description here

Is there a way that I can bring these lines in so that they aren't spread so widely and will fit within the column width? Am I using the wrong type of environment?

I need the second part of the lines to still be right-justified.

2
  • Why not just remove the &? You can use \quad to insert space, and/or use punctuation marks to separate the constraint and the quantifier. Feb 10, 2021 at 2:35
  • I would like the quantifier to be right justified though. I can fiddle around with custom horizontal spacing until it looks okay, but i was wondering if there was a way I could make it line up automatically that way..
    – guskenny83
    Feb 10, 2021 at 3:02

1 Answer 1

1

For the particular problem that you have, it seems it will work if you just let the conditions of the "second line" protrude to the left. Which means that it is a perfect time for \mathllap. (You will need to load the mathtools package.)

You can wrap the quantifiers on the bottom line in \mathllap

\mathllap{\forall  p,q\in \S{P},(i,j) \in E : p \ni (i,j),q \ni i,p \neq q}

so that when computing widths its length will be ignored. Combining the fact that

  1. You are setting this in a right-aligned cell
  2. You are telling it is okay to overlap on the left

the expression with have the right end-point aligned at the alignment point, and go as far left as is needed.

I also took the liberty of removing a bunch of superfluous calls to \displaystyle.

\documentclass{amsart}
\usepackage{mathtools}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{align}
    \text{minimise} \quad & \sum_{p \in \S{P}}\left(\sum_{(i,j) \in E \cap p} c_{ij}\right)z_{p},\\
    \text{subject to} \quad & \sum_{p \in \S{P}}\left(|V\cap p| - |E\cap p|\right)z_{p} = 1,\nonumber\\
        & \sum_{p \in \S{P}}\left(|(S\setminus\{l\}) \cap p| - |E(S)\cap p|\right)z_{p} \geq 0 & \forall\ l \in S \subseteq V,\nonumber\\
        & z_p \leq z_q  & \mathllap{\forall  p,q\in \S{P},(i,j) \in E : p \ni (i,j),q \ni i,p \neq q}\nonumber.
\end{align}    
\end{document}

Notice that since you didn't provide a fully minimum working example, I just used the default amsart class and didn't bother making the equation number go on the right. And also that instead of whatever you defined \S to be, now \S shows the section symbol (its original meaning).

enter image description here

Now, in this case the spacing works out just fine, but there may be similar situations where the reserved blank space between the expression and the quantifiers may be too much or too little; in those cases you may want to look into the alignat environment for more fine-tuning. (For example, if instead of z_p \leq z_q in the first cell of the bottom line, you have something longer, then the above code will cause some overlapping.)


Actually, seeing you are already using some manual spacing, and that I prefer the texts themselves to be left aligned instead of right aligned, here's an alignat example, which still uses the the \mathllap trick.

\begin{alignat}{3}
    &\text{minimise} & \quad & \sum_{p \in \S{P}}\left(\sum_{(i,j) \in E \cap p} c_{ij}\right)z_{p},\\
    &\text{subject to} & & \sum_{p \in \S{P}}\left(|V\cap p| - |E\cap p|\right)z_{p} = 1,\nonumber\\
        && & \sum_{p \in \S{P}}\left(|(S\setminus\{l\}) \cap p| - |E(S)\cap p|\right)z_{p} \geq 0 & \qquad \forall\ l \in S \subseteq V,\nonumber\\
        && & z_p \leq z_q  & \mathllap{\forall  p,q\in \S{P},(i,j) \in E : p \ni (i,j),q \ni i,p \neq q}\nonumber.
\end{alignat}

The result:

enter image description here

Notice how "minimize" and "subject to" are now left-aligned, instead of right-aligned as what you had, and the slightly more compact spacing between the expression and quantifiers on lines 3 and 4.

1
  • excellent answer! thanks, that is exactly what I wanted. thanks for the multiple methods as well..
    – guskenny83
    Feb 10, 2021 at 23:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .