Given a macro that accepts a matrix as an argument
\newcommand{tabler}[1]{\matrix(m)[matrix of nodes, ampersand replacement=\&]{#1};}
I would like to determine the number of columns in matrix m, to be able to iterate over them, starting from the highest column.
Background/Motivation:
Given a list of column widths of size n, and a (* x m) matrix, I want to apply the column widths to the columns of the matrix, starting with column m - n +1.
Visualizing what I'm trying to do:
\tabler{col 1\&col 2\&col 3\&col 4}{3,1,3}
|--col 1--|--col 2--|--col 3––|--col 4––|
| width 3 | width 1 | width 3 |
Having determined the highest column, I would iterate over the columns, similar to the technique used here, starting from the top, and apply the column styles in reverse order.
Edit for clarification:
Effectively, I'm trying to apply the list of column widths to the n right-most columns. I don't know how to directly access the highest column with the tikz style command column x/.stlye which is 1-indexed. Python-style list indexing (where l[-1] returns the last element of list l) would be similarly helpful.
Update: Following @Kevin C's pointer to the \pgf@matrix@numberofcolumns macro, I tried (unsuccessfully) to print the number of columns in the matrix by using the pgfkeys .store in key handler (but don't fully understand the expansion rules to be honest).
Example code:
\documentclass{scrartcl}
\usepackage{xparse, tikz}
\usetikzlibrary{matrix}
\makeatletter
\newcommand\totcol{\pgf@matrix@numberofcolumns}
\makeatother
\pgfkeys{
/tabler/execute macro/.style = {/tabler/save/.expand once=#1},
/tabler/save/.store in=\numcols
}
\NewDocumentCommand\tabler{m}{
\matrix(m)[/tabler/execute macro={\totcol},
matrix of nodes,
ampersand replacement=\&] at (0,0)
{#1};
\node at (0,0) {\numcols{}};
}
\begin{document}
\begin{tikzpicture}
\tabler{a \& b\& c \& d \& e\\}
\end{tikzpicture}
\end{document}
This fails with Undefined control sequence [...] \numcols — what am I missing?
Please let me know if there are better/more elegant ways to accomplish what I've outlined.

\tablersuggests that it takes one argument, but when you use it later,\tablerseems to take two arguments. I don't quite understand whatnis. And what is its relation to{3,1,3}? – Herr K. Jan 30 '15 at 22:00{3,1,3}). If the matrix has 5 columns, the columns 3-5 should have minimum widths of{3,1,3}, respectively. – Julian Jan 30 '15 at 22:16