17

I asked this question at stackoverflow and have been kindly redirected here.

I'd like to align some equations in Latex using the AMS packages. Each equation has two equal signs that need to be aligned. So something in the line of

A = B = C
D = E = F

I've tried using the align-environment like this

\begin{align}
A &= B &= C \\
D &= E &= F
\end{align}

This works in principle (it aligns), however it adds ridiculously large spaces before the second equal sign in each line. But I just want the line to runs as if there was no additional alignment tab. Only when I replace for example "B" by "BBB" I want the equal sign before "F" to shift to right the exact amount of space.

Could anyone help me out on that one? It's kind of driving me crazy since I don't get the idea of that strange behavior and I just can't find any solution. Maybe alignat could help, but I don't really get how that environment works.

Cheers, Oliver

5
  • 2
    This has already been asked today and is answered here.
    – Caramdir
    Commented Dec 5, 2010 at 23:01
  • 1
    Note that the align environment should typically be used with an even number of cells, like \begin{align}x &=1 & y &= 2 \\...\end{align}.
    – Caramdir
    Commented Dec 5, 2010 at 23:02
  • @Caramdir: Ah, I see. At least the other question doesn't refer to alignat or explain the ampersands. Hm :) I'll let my answer here for now in the hope it helps the questioner.
    – Stefan Kottwitz
    Commented Dec 5, 2010 at 23:08
  • Thanks. I actually ran across this post when searching. But I obviously messed up when trying to apply it to my problem. Seems I neglected the "even number of cells" rule (which I didn't know of).
    – janitor048
    Commented Dec 5, 2010 at 23:15
  • @Caramdir: I'd say it's not a duplicate, so don't close: It's not specified in the question that the middle column should be centered, so the answer is simpler. Commented Dec 6, 2010 at 13:43

2 Answers 2

13

The ampersand & does not only mark alignment positions, it further separates columns. So, with alignat, your example could look like:

\begin{alignat}{2}
A &= B & &= C \\
D &= E & &= F
\end{alignat}

The agument to alignat stands for the number of columns.

3
  • Cool. Using your example the second column actually gets left-aligned when expanding BBBB. When using the notation from the post Caramdir referred to, it is right aligned. Plus I need a ={} for the first equal sign. Is the argument to alignat really the number of columns? In this example it's 3 columns, isn't it (or four, if you count that blind column).
    – janitor048
    Commented Dec 5, 2010 at 23:19
  • 4
    @janitor048: A &= B is the first column, &= C is the second column. The & within those columns determines the alignment position. Unfortunately the & has two different meanings here.
    – Stefan Kottwitz
    Commented Dec 5, 2010 at 23:22
  • Ah, I see. Thanks a lot. I always thought the alignment and the creation of columns was done with the same &. Now this stuff makes much more sense.
    – janitor048
    Commented Dec 5, 2010 at 23:29
2

(Cross-posted from https://stackoverflow.com/a/53842127/5445670)

What about using array with a custom separator?

\begin{array}{r@{\ }c@{\ }l}
A &= B &= C \\
D &= E &= F
\end{array}

You must log in to answer this question.

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