2

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!

David Carlisle
  • 757,742
tchakravarty
  • 2,427
  • 3
  • 26
  • 45

1 Answers1

8

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}
David Carlisle
  • 757,742