I am trying to replicate the same exact output as plain math mode would give
for a simple polynomial formula but using \matrix
because I want to
right-align the terms in the polynomial or leave some of them blank. I can't use \alignat
either for other reasons.
I have made some progress but the spacing is hard to get right. In the
following picture you can see the output in plain math mode, using
\alignat
and my attempt using \matrix
(I use the convenience macro
\arr
).
As you can see, my version is somewhat off. I think the biggest error is in the spacing around the equals sign.
\documentclass[a4paper,11pt]{article}
\usepackage{amsmath}
\makeatletter
% http://tex.stackexchange.com/questions/2233/
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols r]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\newcommand{\arr}{\@ifstar\arr@star\arr@nostar}
\newcommand{\arr@nostar}[2][*\c@MaxMatrixCols r]{%
\begin{bmatrix}[#1]#2\end{bmatrix}%
}
\newcommand{\arr@star}[2][*\c@MaxMatrixCols r]{%
\begin{matrix}[#1]#2\end{matrix}%
}
\makeatother
\begin{document}
\begin{equation}
C + 3D = 2
\end{equation}
%
\begin{alignat}{3}
C &+{}& 3D &={}& 2 & \notag
\end{alignat}
%
\begin{equation}
\arr*[@{}r@{\,}c@{\,}r@{\,}c@{\,}r@{}]{
C &+{}& 3D &=& 2 \notag
}
\end{equation}
\end{document}