# Double alignment causing unwanted spacing

A way to define an operator would be that of writing double align, namely

\begin{align*}
f \colon A & \longrightarrow B, \\
a & \longrightarrow f(a),
\end{align*}


as first, and then specify

\begin{align*}
f(a) \colon C & \longrightarrow D, \\
c & \longmapsto a \cdot c.
\end{align*}


What I would like to do is merging the two alignments in f(a) keeping the arrows aligned with each other.

I went with alignat as follows

\begin{alignat*}{2}
f \colon A &\longrightarrow B & \\
a & \longmapsto f(a)\colon C & \longrightarrow D \\
& c & \longmapsto a\cdot c.
\end{alignat*}


which outputs

I tried to move around all of the &, but any of the adjustments seemed to fix the alignments, nor spacings.

Any help would be appreciated.

You need to understand that the align(at) environment requires two ampersands per alignment column, but the first. Here is code which does what you want, if I've well understood:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{alignat*}{2}
f \colon A &\longrightarrow B & \\
a & \longmapsto f(a)&\colon C & \longrightarrow D \\
& & c & \longmapsto a\cdot c.
\end{alignat*}

\end{document}


• This works fine in this example, thanks. Unfortunately, that's a MWE, in my actual work things are a little different. Suppose instead of "B" there was written "Bernard". In that case, the colon in the second line would shift to the right, causing again an absurd spacing between itself and f(a). Same issue goes if I substitute "c" in the last line with "corner". Nov 20, 2020 at 8:28
• In this case, you might load mathtools in the place of amsmath (it is an extension of the latter), and use \mathrlap{Bernard} in the first line and\mathlap{corner} in the last line, so as to neutralise their lengths. Nov 20, 2020 at 9:18