[Tex/LaTex] Typesetting a long exact sequence

alignhorizontal alignmentmath-mode

I am trying to typeset the Mayer-Vietoris sequence (concisely – without the map names above the arrows). Currently I am simply using the AMS align environment with a bunch of \rightarrow, \cdots and a \hphantom to align the last line horizontally:

\begin{align*}
\cdots & \rightarrow H_{n}\left(A\cap B\right)\rightarrow H_{n}\left(A\right)\oplus H_{n}\left(B\right)\rightarrow H_{n}\left(X\right)\rightarrow \\
 & \rightarrow H_{n-1}\left(A\cap B\right)\rightarrow\cdots \\
 & \hphantom{\rightarrow H_{n}\left(A\cap B\right)\rightarrow H_{n}\left(A\right)\oplus H_{n}\left(B\right)}\cdots\rightarrow H_{0}\left(X\right)\rightarrow 0
\end{align*}

The result looks like this:

mv1

I would like to align the first arrow on the last line correctly under the penultimate arrow on the first line, and also to merge the last line with the second one, so it looks like this (image made with image editor):

mv2

How should I do this?

Best Answer

Here is a possible solution using the package mathtools (which is kind of a successor of amsmath):

% arara: pdflatex

\documentclass{article}
\usepackage{mathtools}

\begin{document}    
    \begin{alignat*}{2}
        \cdots &\rightarrow H_{n}(A\cap B)\rightarrow H_{n}(A)\oplus H_{n}(B) &&\rightarrow H_{n}(X)\rightarrow \\
        &\rightarrow H_{n-1}(A\cap B)\rightarrow\cdots &&\mathllap{\cdots}\rightarrow H_{0}(X)\rightarrow 0
    \end{alignat*}  
\end{document}

enter image description here

A short explanation:

I used an alignat with two alignment points (as requested by you). First, I tried to push the \cdots to the right with \hfill but this does not work here. For sure you could find some array solution with this trick.

Therefore, I had to add the dots to the right of the second alignment mark and change its width to zero. The command \mathllap is provided by mathtools and smashes the box width setting its content to the left.