## Automatically counting table rows

I’ve just read the blog post Automatic Table Row Numbers in LaTeX by Alexander O’Connor, while reading it came to my mind how to use a feature of the array package to automatize such tasks. The array syntax >{command} allows to include commands in row formating parameters that will be executed with each cell. Here’s a short compilable demonstration example:

\documentclass[a4paper,10pt]{article} \usepackage{array} \newcounter{rowno} \setcounter{rowno}{0} \begin{document} \begin{tabular}{>{\stepcounter{rowno}\therowno.}cl} \multicolumn{1}{r}{No.} & text \\\hline & first \\ & second \\ & third \\ & fourth \end{tabular} \end{document}

Output:

Of course it would be only useful with longer tables. But this example is also intended to show how to execute commands for certain cells in general.

10. September 2009 by stefan
Categories: Uncategorized | 1 comment