nesting enumerated list environment within a table

650 views
Skip to first unread message

jrothim

unread,
Apr 7, 2008, 11:43:55 AM4/7/08
to LaTeX Users Group
I am interested in nesting an enumerate environment within a table.
The obvious thing I tried is:

\begin{table}[htb] \centering
\caption{Syrup production}
\label{tab:syrup}
\begin{tabular}[c]{|c|c|} \hline
\begin{enumerate}
\item Massachusetts \label{ma} & 30,000 gallons \\
\item Vermont \label{vt} & 50,000 gallons \\
\item New Hampshire \label{nh} & 60,000 gallons \\
\end{enumerate}
\end{tabular}
\end{table}

Unfortunately latex gave an error at the \item commands. I tried
moving the enumerate environment outside the table, but that didn't
work either. The \labels are desired to reference the numbering used
in the table elsewhere in the text.

Anyone know a some other way to do this?

Thanks!
Jeff

Werner Grundlingh

unread,
Apr 7, 2008, 12:50:04 PM4/7/08
to LaTeX Users Group
If there is no requirement to place the enumerate environment inside a
table, the following works for me and allows to reference the
enumerate \item entries via \label{...} and \ref{...} combinations:

\begin{enumerate}
\item Massachusetts \label{ma} 30,000 gallons
\item Vermont \label{vt} 50,000 gallons
\item New Hampshire \label{nh} 60,000 gallons
\end{enumerate}

We can refer to item~\ref{ma}, \ref{vt} or even \ref{nh}.

Hope this helps,
Werner

jrothim

unread,
Apr 8, 2008, 11:47:24 AM4/8/08
to LaTeX Users Group
Thanks for the response. I was indeed hoping to nest it within a
table with rows, columns, lines, etc. But getting (referenceable)
numbering within the table cells was beyond my latex knowledge base.
I imagine there is a way. Any ideas or prior work out there would be
appreciated.

Werner Grundlingh

unread,
Apr 9, 2008, 5:19:57 PM4/9/08
to LaTeX Users Group
On Apr 8, 8:47 am, jrothim <jrot...@yahoo.com> wrote:
> Thanks for the response.  I was indeed hoping to nest it within a
> table with rows, columns, lines, etc.  But getting (referenceable)
> numbering within the table cells was beyond my latex knowledge base.
> I imagine there is a way.  Any ideas or prior work out there would be
> appreciated.

Hey Jeff,

Here is one alternative solution to your problem. I created a new
counter (citycntr) that keeps track of your cities, and labels them so
that you can reference them at a later stage. The command used to
identify cities is
\city{<name of city>}{<label for city>}
where both arguments are required. If you want the label to be
optional, one can also do that. However, for now, I thought this would
suffice...

\documentclass{article}

\begin{document}

\newcounter{citycntr}
\renewcommand{\thecitycntr}{\arabic{citycntr}}
\newcommand{\city}[2]{%
\refstepcounter{citycntr}%
\thecitycntr.\ #1 \label{#2}
}

\begin{table}[htb]
\centering
\caption{Syrup production}
\label{tab:syrup}
\begin{tabular}{|c|c|} \hline
\city{Massachusetts}{ma} & 30,000 gallons \\
\city{Vermont}{vt} & 50,000 gallons \\
\city{New Hampshire}{nh} & 60,000 gallons \\ \hline
\end{tabular}
\end{table}

If you ever visit city~\ref{ma} or~\ref{nh}, then you do not have to
visit city~\ref{vt}.

\end{document}

Hope this helps,
Werner
Reply all
Reply to author
Forward
0 new messages