# Numbering and aligning an equation with multiple columns

I search a way to align an equation with multiple columns where the following criteria should be met:

• The equation tag should be in the last line

• The equal signs should be centered and aligned

Using alignat gives me the right numbering but I have been unable to center the last equal sign in the second row as it is overset with a reference. Using array inside an equation I can get the alignment correct (although with more space between the columns) but the numbering is now centered and not at the end.

\documentclass{book}
\usepackage{amsmath}
\renewcommand\theequation{\thesection.\arabic{equation}}

\begin{document}
\chapter{}
\section{Section}
\subsection{subsection}
\begin{equation}
1 + 1 = 2
\label{eq:1}
\end{equation}

\begin{alignat}{3}
E =& n^\mu n^\nu T_{\mu\nu} &&=&& \rho \notag \\
T =& T^\mu_\mu = -\rho + p_r + 2 p_\perp
&&\overset{(\ref{eq:1})}{=}&& 2 (p_\perp -\rho) \notag \\
S =& T+E &&=&& 2 p_\perp - \rho \notag \\
p^\mu =& - \gamma^{\mu \alpha} n^\beta T_{\alpha \beta} &&=&& 0 \quad .
\end{alignat}

\begin{equation}
\begin{array}{cclcl}
E &=& n^\mu n^\nu T_{\mu\nu} &=& \rho  \\
T &=& T^\mu_\mu = -\rho + p_r + 2 p_\perp
&\overset{(\ref{eq:1})}{=}& 2 (p_\perp -\rho)  \\
S &=& T+E &= & 2 p_\perp - \rho  \\
p^\mu &=& - \gamma^{\mu \alpha} n^\beta T_{\alpha \beta} &= & 0 \quad .
\end{array}
\end{equation}

\end{document}


## 2 Answers

My answer https://tex.stackexchange.com/a/136374/15925 may be adapted to introduce a command \cmdcol for material to be centered in a column in display math in alignat and related environments: \documentclass{book}

\usepackage{mathtools}
\numberwithin{equation}{section}

\makeatletter
\newcommand{\cmdcol}{\omit\hfil\strut@ $$\m@th\displaystyle #1$$\hfil}
\makeatother

\begin{document}

\chapter{}
\section{Section}
\subsection{Subsection}

\begin{equation}
1 + 1 = 2
\label{eq:1}
\end{equation}

\begin{alignat}{2}
E &= n^\mu n^\nu T_{\mu\nu} &\cmdcol{=}& \rho \notag \\
T &= T^\mu_\mu = -\rho + p_r + 2 p_\perp
&\cmdcol{\overset{\eqref{eq:1}}{=}}& 2 (p_\perp -\rho) \notag \\
S &= T+E &\cmdcol{=}& 2 p_\perp - \rho \notag \\
p^\mu &= - \gamma^{\mu \alpha} n^\beta T_{\alpha \beta} &\cmdcol{=}& 0 \quad .
\end{alignat}

\end{document}


The structure of the \cmdcol command is built up to mimic the standard ams definition for columns in align and friends.

By the way, your numbering scheme is better effected by \numberwithin. I have switch to mathtools rather than amsmath for the further extensions provided by that package, it loads amsmath anyway.

Your idea with array is good, but needs some refinement. However, I wouldn't set the equation number above the equals sign, but on the side. I'll show both ways.

\documentclass{book}
\usepackage{amsmath,array}
\newcolumntype{R}{>{\displaystyle}r}
\newcolumntype{C}{>{\displaystyle{}}c<{{}}}
\newcolumntype{L}{>{\displaystyle}l}

\renewcommand\theequation{\thesection.\arabic{equation}}

\begin{document}
\chapter{Title}
\section{Section}
\subsection{subsection}
\begin{equation}
1 + 1 = 2
\label{eq:1}
\end{equation}

\begin{equation}
\renewcommand{\arraystretch}{1.3}
\setlength{\arraycolsep}{0pt}
\begin{array}[b]{RCLCL}
E &=& n^\mu n^\nu T_{\mu\nu} &=& \rho,  \\
T &=& T^\mu_\mu = -\rho + p_r + 2 p_\perp
&\overset{(\ref{eq:1})}{=}& 2 (p_\perp -\rho),  \\
S &=& T+E &= & 2 p_\perp - \rho,  \\
p^\mu &=& - \gamma^{\mu \alpha} n^\beta T_{\alpha \beta} &= & 0.
\end{array}
\end{equation}

\begin{equation}
\begin{alignedat}[b]{3}
E     &= n^\mu n^\nu T_{\mu\nu}                        &&= \rho, \\
T     &= T^\mu_\mu = -\rho + p_r + 2 p_\perp           &&= 2 (p_\perp -\rho),
&&\quad\text{by \eqref{eq:1}} \\
S     &= T+E                                           &&= 2 p_\perp - \rho,  \\
p^\mu &= -\gamma^{\mu \alpha} n^\beta T_{\alpha \beta} &&= 0.
\end{alignedat}
\end{equation}

\end{document} 