Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.)

share|improve this question
add comment

1 Answer

up vote 20 down vote accepted

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}

enter image description here


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.

enter image description here


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.

https://bitbucket.org/martin_scharrer/adjustbox/changeset/943f7cb95271

\documentclass{article}
\usepackage{array}
\usepackage{adjustbox}
\newcounter{rowcount}
\setcounter{rowcount}{0}
\usepackage[framemethod=tikz]{mdframed}
\begin{document}
\adjustbox{bgcolor=black, tabular=@{\stepcounter{rowcount}\makebox[3em][r]{\color{white}\therowcount.)}\hspace*{\tabcolsep}}>{\color{white}}l>{\color{white}}l}{% 
foo & bar\\
foo & bar\\
foo & bar\\
foo & bar\\
foo & bar\\
foo & bar\\
} 

\end{document}

enter image description here

share|improve this answer
    
How to make the number in DESC order? –  I am who I say I am Jun 3 '12 at 13:35
    
@Forgiver: What is DESC order? –  Marco Daniel Jun 3 '12 at 13:37
    
From the highest number to the lowest. –  I am who I say I am Jun 3 '12 at 13:39
1  
@Forgiver: Therefor you can use the package totcount. See also: tex.stackexchange.com/questions/58221/… –  Marco Daniel Jun 3 '12 at 13:41
1  
@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
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.