I'm trying to replicate the row/column indexing behaviour presented in Counters for use in array/tabular cells using collcell. However, the collection and printing mechanism (and therefore any conditioning, if necessary) becomes out-of-sync.
\documentclass{article}
\usepackage{collcell}
\makeatletter
\def\insert@column{%
\the@toks \the \@tempcnta
\global\advance\c@tabcol\@ne
\ignorespaces \@sharp \unskip
\the@toks \the \count@ \relax}
\let\old@arraycr\@arraycr
\def\@arraycr{\global\c@tabcol\z@\global\advance\c@tabrow\@ne\old@arraycr}
\let\old@tabarray\@tabarray
\def\@tabarray{\global\c@tabrow\@ne\global\c@tabcol\z@\old@tabarray}
\makeatother
\newcounter{tabcol}\newcounter{tabrow}
\newcommand{\tabrowcol}[1]{(\thetabrow,\thetabcol)}
\newcolumntype{C}{ >{\collectcell\tabrowcol}c<{\endcollectcell} }
\begin{document}
\[
% Correct row/column indexing
\begin{array}{ c c c }
(\thetabrow,\thetabcol) & (\thetabrow,\thetabcol) & (\thetabrow,\thetabcol) \\
(\thetabrow,\thetabcol) & (\thetabrow,\thetabcol) & (\thetabrow,\thetabcol) \\
(\thetabrow,\thetabcol) & (\thetabrow,\thetabcol) & (\thetabrow,\thetabcol)
\end{array}
\qquad
% Incorrect row/column indexing
\begin{array}{ C C C }
x & x & x \\
x & x & x \\
x & x & x
\end{array}
\]
\end{document}
How can I adapt collcell so that the right matrix matches the left matrix?

\stepcounter{tabcol}in the definition of theCcolumn type. However, the last column is processed too late and you get 0. You need a “phantom column” at the end; but I remember something about the last column in the manual ofcollcell. – egreg Oct 26 '16 at 07:30