# How can I align multiple aligned environments?

I have this equations:

\begin{align}
\begin{aligned}
x&=y & z&=w & k&=j \\
a&=b & c&=d & e&=f \\
\end{aligned}
\\
\begin{aligned}
x+a&=y+b & z+c&=w+d & z+x&=b \\
a+q&=b+w & c+e&=d+r & e+t&=f+y \\
\end{aligned}
\end{align}


I want all columns to be aligned each others like in the following example:

I have tried to adjust spaces by hands in the following horrible way:

\begin{align}
x&=y & z&=w & k&=j\nonumber\\[-.25\baselineskip]
\\[-.75\baselineskip]
a&=b & c&=d & e&=f
\nonumber\\
x+a&=y+b & z+c&=w+d & z+x&=b\nonumber\\[-.25\baselineskip]
\\[-.75\baselineskip]
a+q&=b+w & c+e&=d+r & e+t&=f+y\nonumber
\end{align}


Is there a TeXnician solution to do this?

• Please clarify what you're trying to achieve. Should the first three rows of equations be given just 1 equation number, while giving another number to the final row?
– Mico
Commented Sep 11, 2019 at 14:29
• Is placing the (C.17) and (C.18) equation numbers slightly above rows 2 and 4 intentional?
– Mico
Commented Sep 11, 2019 at 14:36
• If you can put them in all in one environment, use alginat instead. Otherwise you need to determine the widest element of each and then use \makebox. Commented Sep 11, 2019 at 14:36
• @Mico I have placed equation numbers by hands as try. First two equations are numbered as C.17, second two as C.18. Commented Sep 11, 2019 at 14:44
• @PeterGrill Please, could you give to me a suggestion? Commented Sep 11, 2019 at 15:20

You need to capture the widths of the widest elements in each of your equations. Then you can use those widths to impose alignment between elements that aren't as wide.

Below I use a slight modification to eqparbox via \eqmathbox[<tag>][<align>]{[itex]} which stores the maximum width of each <tag>ged box with varying [itex] content. Within the box you can change the <align>ment as needed (left, centre or right).

\documentclass{article}

\usepackage{eqparbox,xparse,amsmath}

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
\IfValueTF{#1}
{\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
{\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
\mathpalette\eqmathbox@{#3}
}
\makeatother

\begin{document}

\begin{gather}
\begin{aligned}
\eqmathbox[ll][r]{x} &= \eqmathbox[lr][l]{y} &
\eqmathbox[cl][r]{z} &= \eqmathbox[cr][l]{w} &
\eqmathbox[rl][r]{k} &= \eqmathbox[rr][l]{j} \\
a &= b & c &= d & e &= f \\
\end{aligned}
\\
\begin{aligned}
x + a &= \eqmathbox[lr]{y + b + c} &
\eqmathbox[cl]{z + c + e} &= w + d &
z + x &= \eqmathbox[rr]{b + i + j} \\
\eqmathbox[ll]{a + q + d} &= b + w &
c + e &= \eqmathbox[cr]{d + r + o} &
\eqmathbox[rl]{p + e + t} &= f + y
\end{aligned}
\end{gather}

\end{document}