Automatically counting table rows
10 September 2009 by Stefan Kottwitz
I’v 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.
This entry was posted on 10 September 2009 at 4:19 PM and is filed under Figures and Tables, LaTeX General. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.




14 September 2009 at 11:12 AM
[…] blog TeXblog: Automatically counting table rowsTeXblog: DANTE autumn conference 2009Got Emacs?: Getting Slide or Frame numbers in Beamer Warsaw […]