# How to enumerate the rows of a table

I want to automatically enumerate the text rows of a table. Is there an option within tabular, or another package? (Of course I do not want the rules to be enumerated.)

-
Duplicate question: Automatic table row numbers – koppor Oct 20 at 13:02

First define your own counter -- in this case rowcount. Now you can use the the declaration by @{} to print out the counter:

Here the code:

\documentclass{article}
\usepackage{array}
\newcounter{rowcount}
\setcounter{rowcount}{0}
\begin{document}

\begin{tabular}{@{\stepcounter{rowcount}\therowcount.)\hspace*{\tabcolsep}}ll}
foo & bar\\
foo & bar\\
foo & bar\\
foo & bar\\
foo & bar\\
foo & bar\\
\end{tabular}

\end{document}


EDIT

The alignment of the row numbers can be down by adding a \makebox with a specific with and adjustment.

\makebox[3em][r]{\therowcount.)}


In this case the number rowcount will be printed in a box with a width of 3em and right aligned.

Colored Background

To get a colored background you can use packages like tcolorbox, framed, mdframed or adjustbox

Here an example with adjustbox. Unfortunately there is no fontcolor option.

In the newest of of adjustbox the author Martin Scharrer provided a new key fgcolor to setup the font color of the environment.

\documentclass{article}
\usepackage{array}
\newcounter{rowcount}
\setcounter{rowcount}{0}
\usepackage[framemethod=tikz]{mdframed}
\begin{document}
foo & bar\\
foo & bar\\
foo & bar\\
foo & bar\\
foo & bar\\
foo & bar\\
}

\end{document}


-
How to make the number in DESC order? – kiss my armpit Jun 3 '12 at 13:35
From the highest number to the lowest. – kiss my armpit Jun 3 '12 at 13:39
@Forgiver: Therefor you can use the package totcount. See also: tex.stackexchange.com/questions/58221/… – Marco Daniel Jun 3 '12 at 13:41
@Chernoff you can use \roman{\therowcount} to get lowercase roman numerals. Other options are \Roman{} for upper case roman numeral (I, II, ...), \alph{} for lower case letters (a, b, ...) and \Alph{}. Default is \arabic{}. – mythealias Dec 8 '12 at 19:52
@MarcoDaniel Daniel I have a \hline between all of my rows. This also gets a number using this method. Is there a way to make the numbering skip rows like this? – David Doria Jul 7 '14 at 14:11