# Left-align all columns in equation

I am trying to align 3 columns of an equation using the aligned block:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{aligned}
a[i:j] &= \langle\rangle                &\text{if } i > j \\
a[i:j] &= \langle a_i, ..., a_j \rangle &\text{if } a = \langle a_0, ..., a_i, ... a_j, ... \rangle \\
a[i:]  &= \langle a_i, ... \rangle      &\text{if } a = \langle a_o, ..., a_i, ... \rangle
\end{aligned}
\end{equation*}
\end{document}


This results in the 2nd column being left-aligned, but the 1st and 3rd being right-aligned.

I would like for all of them to be left-aligned, like this:

Just expanding a bit on @vonbrand's answer ...

The alignat environment is an extension of the align environment. It uses the & alignment symbol to align the blocks in alternating left and right manner.

• If two left-aligned blocks are supposed to follow each other, use && rather than &.

• You can create extra space between two left-aligned blocks by inserting \quad or \qquad between the consecutive & symbols.

• The alignat environments requires an argument, an integer. To calculate this integer, take the maximal number of & symbols in any row, add 1, and divide by 2. In the example below, the maximal number & symbols is 5; adding 1 and dividing by 2 gives 3. (If the maximal number is an even number, add 1 before proceeding.)

Some additional comments: I would replace all instances of ... with \dots in order to create typographical ellipses; and I'd encase the 3 : symbols in curly braces in order to avoid the extra spacing that otherwise gets inserted.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat}{3} % max. # of '&' symbols in any row: 5. (5+1)/2 = 3
& a[i{:}j] &&= \langle\,\rangle
&\qquad&\text{if $i > j$} \\ % or '\quad', if you prefer
& a[i{:}j] &&= \langle a_i, \dots, a_j \rangle
&&\text{if $a = \langle a_0, \dots, a_i, \dots a_j, \dots \rangle$} \\
& a[i{:}]  &&= \langle a_i, \dots \rangle
&&\text{if $a = \langle a_o, \dots, a_i, \dots \rangle$}
\end{alignat}
\end{document}

• Hi, is there particular reason why you use \text{if $i > j$} rather than \text{if } i > j ?
– Surb
Commented Sep 16, 2020 at 12:11
• @Surb - The reason is syntactic: the entire string if $i > j$ forms a sentence (fragment). To get the balance of text and math mode right, it's necessary to encase this sentence in a \text "wrapper", i.e., write it as \text{if $i > j$}. It's true that the outputs of \text{if $i > j$} and \text{if } i > j are the same, but this is more a happy coincidence than truly a consequence of deliberate design of [$]\text{if } i > j[$]. In a LaTeX document, it's almost always a good idea to emphasize the syntactic structure and to avoid visual formatting as much as possible.
– Mico
Commented Sep 16, 2020 at 12:44
• @Mico Are you avoiding syntax highlighting on purpose? Please, don't edit old answers: you're filling the main page with bumps of old threads, with no real advantage. Commented Sep 27, 2020 at 15:43
• @egreg - I truly cannot stand the new code coloring system that the site's powers-that-be have foisted on us. It contains semantic errors and inconsistencies, and it makes code look like as gaudy as an overdecorated Christmas tree. Better no coloring at all than bad coloring... But I'll stop now de-coloring old answers. (I will de-color my new answers, though.)
– Mico
Commented Sep 27, 2020 at 15:57
• @Mico I agree that it's anything but pretty. Commented Sep 27, 2020 at 16:02

Use alignat, and read the documentation carefully. It has quite funny ideas of how to align column contents, you have to pick the ones to fill with some care. A bit of experimentation (and some dummy columns, perhaps for spacing only) will get you the results you desire.