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.

How can I have a column in a tabular environment so that the first column is automatically produced? Something like this:

\begin{table}
\begin{tabular}{lc}
Step  & Comments \\
1st & a \\
2nd & b \\
3rd & c \\
4th & d 
\end{tabular}
\caption{}\label{}
\end{table}

Here I am envisaging that the first column is auto-generated and all I have to do is place an \item or some other iterator there. The first row is the column header. Any help getting started would be great!

share|improve this question
    

1 Answer 1

up vote 8 down vote accepted

You can use the array package to insert a counter increment into the cell:

enter image description here

\documentclass{article}

\usepackage{array}

\newcounter{mycount}
\renewcommand\themycount{%
\arabic{mycount}%
\ifcase\value{mycount}%
th\or st\or nd\or rd\else th\fi}

\begin{document}

\begin{table}
\begin{tabular}{>{\refstepcounter{mycount}\themycount}lc}
\multicolumn{1}{c}{Step}  & Comments \\
 & a \\
 & b \\
 & c \\
 & d 
\end{tabular}
\caption{}\label{}
\end{table}

\end{document}
share|improve this answer
    
Thanks David. Could you explain what part of the code makes the counter skip the first row? –  fg nu Oct 15 '12 at 11:24
1  
the \multicolumn{1} replaces the preamble template for the first cell by a simple c so it loses the counter code. –  David Carlisle Oct 15 '12 at 11:28

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.