[Tex/LaTex] Equation environment for centered, equally-spaced columns of expressions

amsmathhorizontal alignmentmath-mode

I want a environment for displaying rows and columns of mathematical expressions, such that the contents of each column is centered, and the columns are equally spaced. Rows must have optional equation numbers, as with the align* environment.

I posted a similar question a few months ago, answered here:
Standard math environment for equally-spaced columns of expressions?

Although I accepted the answer there at the time, it has some shortcomings: I have to specify in advance how many columns I'm going to need (unlike the existing align* environment, for example), and it doesn't allow me to have equation numbers for rows in a straightforward way.

Edit on 3rd April 2012: The syntax has to be like this:

\begin{newenvironment}
A & B & C
\\
\nonumber
f & g & h
\end{newenvironment}

This should produce two lines of displayed mathematics in three columns, all equally-spaced from the page margins and from each other. The first line should have an equation number, the second shouldn't.

Best Answer

Ok, the following is probably as dirty as it could ever get, and I have to admit I patched it together by trial&error, but at least it might invoke the spirits-that-be to find a better solution.

Try

\documentclass{article}

\usepackage{amsmath}

\usepackage{etoolbox}

\makeatletter
\def\calign@preamble{%
   &\hfil\strut@
    \setboxz@h{\@lign$\m@th\displaystyle{##}$}%
    \ifmeasuring@\savefieldlength@\fi
    \set@field
    \hfil
    \tabskip\alignsep@
}
\let\cmeasure@\measure@
\patchcmd\cmeasure@{\divide\@tempcntb\tw@}{}{}{}
\patchcmd\cmeasure@{\divide\@tempcntb\tw@}{}{}{}
\patchcmd\cmeasure@{\ifodd\maxfields@
  \global\advance\maxfields@\@ne
  \fi}{}{}{}    
\newenvironment{calign}
{%
  \let\align@preamble\calign@preamble
  \let\measure@\cmeasure@
  \align
}
{%
  \endalign
}  
\makeatother

\begin{document}

\begin{calign}
  A & \min(B,Z) & C
\\
\nonumber
f & g & h
\end{calign}

\end{document}

calign example