I'm trying to create a table environment with:
A header row that spans an arbitrary number of columns,
aligned, automatically numbered cells with aligned numbers
uniform spacing between the all numbers and content cells,
and the need to pass only the number of columns and header text as parameters.
I almost have it:
\documentclass[a4paper]{book}
\usepackage{environ}
\usepackage{tabu}
\usepackage{array}
\newcounter{mycounter}
\newcommand{\mycount}{\stepcounter{mycounter}\arabic{mycounter})}
\makeatletter
\edef\numcols{\tabu@nbcols} % allows for arbitrary column span
\makeatother
\newcolumntype{C}{>{\mycount\makebox[1em]}l}
\NewEnviron{mytable}[2]{ % table format, header text
\begin{tabu}{#1}
\multicolumn{\numcols}{c}{#2} \\
\BODY
\end{tabu}
}
\begin{document}
\begin{mytable}{CCCC}{I span all columns.} % cell content chosen at random
83 & some text & $23+7$ & 9999 \\
5000 & more text & $23+7$ & 9999 \\
5000 & 83 & $23+7$ & 9999 \\
\end{mytable}
\end{document}
Compiled:
This almost nails it, the problem is that the cell numbers don't align (I want the parentheses to line up), and that cell numbers with more digits shift the other content to the side, as displayed in the bottom row. What is the best way to fix this?