Discussion:
table and \enumerate
(too old to reply)
willem
2004-11-18 12:07:55 UTC
Permalink
Hi,

I want to use a table in which the rows are numbered,
something like:
1. xxxx yyyyyy 123
2. aaa bb 0

I tried:
\begin{tabular}
\begin{enumerate}
\item xxxxx & yyyyyy \\
...
\end{enumerate}
\end{tabular}

that doesn't work:
! LaTeX Error: Something's wrong--perhaps a missing \item.


is there a 'nice' solution to this ?


thanks in advance,

willem
Xavier Perseguers
2004-11-18 13:52:17 UTC
Permalink
Post by willem
Hi,
I want to use a table in which the rows are numbered,
1. xxxx yyyyyy 123
2. aaa bb 0
\begin{tabular}
\begin{enumerate}
\item xxxxx & yyyyyy \\
...
\end{enumerate}
\end{tabular}
! LaTeX Error: Something's wrong--perhaps a missing \item.
is there a 'nice' solution to this ?
I would start creating a standard table

\begin{tabular}{rlll}
1. & xxxx & yyyyyy & 123 \\
2. & aaa & bb & 0
\end{tabular}

and then create a counter and a new command such as that:

\documentclass{article}

\newcounter{tablecnt}
\newcommand{\tabularentry}[3]{
\addtocounter{tablecnt}{1}
\thetablecnt. & #1 & #2 & #3 \\
}

\begin{document}

\begin{tabular}{rlll}
\tabularentry{xxxx}{yyyyyy}{123}
\tabularentry{aaa}{bb}{0}
\end{tabular}

\end{document}


Xavier Perseguers
Enrico Gregorio
2004-11-18 12:32:04 UTC
Permalink
Post by willem
Hi,
I want to use a table in which the rows are numbered,
1. xxxx yyyyyy 123
2. aaa bb 0
\begin{tabular}
\begin{enumerate}
\item xxxxx & yyyyyy \\
...
\end{enumerate}
\end{tabular}
! LaTeX Error: Something's wrong--perhaps a missing \item.
Of course it doesn't: enumerate is for producing lists,
not tables.

If you absolutely need to have an automatically enumeration,
you have to use a counter.

\newcounter{mylist}
\newcommand{\tabitem}{\stepcounter{mylist}\arabic{mylist}.}
\newenvironment{itabular}
{\setcounter{mylist}{0}\begin{tabular}}
{\end{tabular}}


\begin{itabular}{rlll}
\tabitem & xxxx & yyyyyy & 123\\
\tabitem & aaa & bb & 0
\end{itabular}

If you need to refer to the item numbers, change
\stepcounter into \refstepcounter and use \label
after \tabitem.

Ciao
Enrico
Rita Bylsma
2004-11-18 22:10:10 UTC
Permalink
Post by willem
Hi,
I want to use a table in which the rows are numbered,
1. xxxx yyyyyy 123
2. aaa bb 0
is there a 'nice' solution to this ?
I hate to have to copy the same thing
over and over so:

\newcounter{mylist}

\setcounter{mylist}{0}
\begin{tabular}{@{\protect\stepcounter{mylist}\protect\arabic{mylist}.\hspace{1em}}crl}
xxxx & yyyyyy & 123\\
aaa & bb & 0 \\
xxxx & yyyyyy & 123\\
aaa & bb & 0\\
aaa & bb & 0\\
xxxx & yyyyyy & 123\\
aaa & bb & 0\\
xxxx & yyyyyy & 123\\
aaa & bb & 0\\
aaa & bb & 0\\
aaa & bb & 0\\
xxxx & yyyyyy & 123\\
aaa & bb & 0\\
xxxx & yyyyyy & 123\\
\end{tabular}

Disadvantage of this method:

- No labels possible, but you may not need
them.

Improvents needed:

- Define an environment for it.
- The hspace that all tabulars have at the
beginning has gone. Have to find how
large it should exactly be so that this tabular
looks good in combination with non-numbered
tabulars.
- Getting the numbers aligned differently is
not easy.

Groetjes,
Rita

Loading...