# Horizontal spacing after equation

I have the following snipped in my LaTeX document:

\begin{align}
\sum_{j=1}^{m}x_{ij} &= 1 \text{ for } i = 1,2,...,n
\sum_{i \in P_k}x_{ij} &\leq 1 \text{ for } j = 1,2,...,m \text{; } \forall k
\end{align}


As you can see, the = and \leq are aligned, and there is some conditional text after the RHS of each equation.

As it turns out, the conditional text is also aligned, but only because both RHS's are equal. If my top RHS was equal to, say, 100 and the bottom was 1, then the conditional text would be offset.

I have two questions:

1. How can I align two things at once? I would like the equation to be aligned on the (in)equality, but I also want the conditions to be aligned.
2. How can I keep the equations more-or-less centred on the page, but have the conditional text off towards the right of the page (but still aligned based on their start location.

Example:

This is what I have now:

a(10i) = b for all i
b(j) = a for all j


however this can happen with the way I have it currently laid out:

a(10i) = b for all i
b(j) = a/10 for all j


notice that the different length RHS pushes the condition off.

What I'd like is something like:

a(10i) = b                for all i
b(j) = a/10            for all j


with the equations centred on the page if possible.

Also, if I change the conditional text so they're variable lengths, then they should start at the same point:

a(10i) = b                for all i
b(j) = a/10             for all j > 5


Notice that the equations are centred on the page and aligned on the equality, and the conditions are off towards the right, but still aligned from their start location.

• The simplest would be to use \phantoms{}. So for the case where you had the 100, in the line below I would just use \phantom{00}1. Here is a recent answer I gave that has some details about \phantoms: Aligned, hanging indents in non-monospaced code. Feb 10, 2012 at 2:24

How does the following look?

\begin{align*}
\alpha+\beta\sum_{j=1}^{m}x_{ij}  &=1&     &\text{for}\ i = 1,2,\ldots,n\\
\sum_{i \in P_k}x_{ij}            &\leq1&  &\text{when}\ j = 1,2,\ldots,m \text{;}\ \forall k
\end{align*}


• This works beautifully, but my equation numbers have disappeared from my output pdf and I'm getting an error: Package amsmath Error: Multiple \label's: label 'eqFirstSum' will be lost, and then I'm getting warnings that my 2 labels are undefined. Feb 10, 2012 at 3:29
• Just remove the stars from the beginning and end statements. I just put those in because I felt the equation numbers added nothing to the above image. Compile a couple of times after to get all the references correct in the output. Feb 10, 2012 at 3:56
• @Ozzah: By the way, use \ldots (or \dotc) instead of typing the dots verbatim ....
– Werner
Feb 10, 2012 at 5:34
• can you explain what exactly what helps in keeping spaces? & or \text ? because this is not working for me Oct 22, 2019 at 1:47

The way to have the conditions aligned is as follows:

\documentclass{scrartcl}
\usepackage{amsmath}

\begin{document}
\begin{align}
\sum_{j=1}^{m}x_{ij} &= 1 & \text{ for } i &= 1,2,...,n
\\
\sum_{i \in P_k}x_{ij} &\leq 1 & \text{ for } j &= 1,2,...,m \text{; } \forall k
\\
\sum_{i \in P_k}x_{ij} &\leq 1 &
\\
\sum_{i \in P_k}x_{ij} &\leq 1 & \text{ for } j &= 1,2,...,m \text{; } \forall k
\end{align}
\end{document}


I hope that this example answers your second question as well. Though I have no idea whether it would be possible to align everything using different align environments. As I understand, the amount of free space on the right depents on how much space do you want to leave for the conditions.

You can also use the alignat environment. It is slightly more flexible at aligning things :)

\begin{alignat}{2}
\sum_{j=1}^{m}x_{ij} &= 1 && \text{ for } i = 1,2,...,n
\\
\sum_{i \in P_k}x_{ij} &\leq (1 - \sqrt{23}) && \text{ for } j = 1,2,...,m \text{; } \forall k
\\
\sum_{i \in P_k}x_{ij} &\leq 1 &&
\\
\sum_{i \in P_k}x_{ij} &\leq 1 && \text{ for } j = 1,2,...,m \text{; } \forall k
\end{alignat}


Hope that helps :) You can read about it on the amsmath documentation