[Tex/LaTex] Numbering and aligning an equation with multiple columns

alignalignatarraysequationsnumbering

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}

Best Answer

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:

Sample output

\documentclass{book}

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

\makeatletter
\newcommand{\cmdcol}[1]{\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.

Related Question