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

        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

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: result with desired arrows

New contributor
Giovanni is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Welcome to TeX.SE. – Mico Sep 16 at 4:42

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.

| improve this answer | |

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.

enter image description here

\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$}
| improve this answer | |
  • Hi, is there particular reason why you use \text{if $i > j$} rather than \text{if } i > j ? – Surb Sep 16 at 12:11
  • 2
    @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 Sep 16 at 12:44

Your Answer

Giovanni is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.