32

I would like to have text in one column table with multiple rows, but I need to include an enumerate in one cell. I get errors and read on the Internet the problem is in combining environments with \item. Is there a solution? I haven't found anything yet.

Sample:

...
\begin{tabular}{|l|}
\hline
\textbf{Name:} Foo \\
\hline
\textbf{Main success scenario:} \\ 
\begin{enumerate}
  \item Entry action
  \item next steps\ldots
\end{enumerate}
\hline
\end{tabular}
 ...

Errors:

Illegal unit of measure (pt inserted). \hline (followed by: )   
Misplaced \noalign. \hline (followed by: )  
Missing number, treated as zero. \hline (followed by: ) 
Something's wrong--perhaps a missing \item. \end{enumerate} (followed by: ) 
You can't use `\hrule' here except with leaders. \hline (followed by: )
David Carlisle
  • 757,742
Gabriel Ščerbák
  • 615
  • 2
  • 6
  • 9

2 Answers2

31

Try changing the heading to p{3cm} as shown below:

\documentclass{article}
\begin{document}
\begin{tabular}{|p{3cm}|}
\hline
\textbf{Name:} Foo \\
\hline
\textbf{Main success scenario:} \\ 
\begin{enumerate}
  \item Entry action
  \item next steps\ldots
\end{enumerate}\\
\hline
\end{tabular}
\end{document}
David Carlisle
  • 757,742
yannisl
  • 117,160
  • Thanks, this is an easy solution that works, meanwhile I found it on the web as well (http://en.wikibooks.org/wiki/LaTeX/Tables#Other_environments_inside_tables). However now I would like to avoid absolute width, how to have it adjust to the width of the page or cell content? – Gabriel Ščerbák Feb 20 '11 at 02:24
  • Ok, I found further information here: http://en.wikibooks.org/wiki/LaTeX/Tables#The_tabular_environment – Gabriel Ščerbák Feb 20 '11 at 02:33
  • @YiannisLazarides: Thanks for the answer. Reading about tabular, I could understand the definitions but still not quite get why one could not replace [c] or [l] for that matter with {|p(3cm)|} at the top...it gives an error message – Abhimanyu Arora Aug 14 '14 at 17:26
  • 1
    @AbhimanyuArora The definition of a list in LaTeX kernel uses paragraphs and paragraph related commands, hence require the |p{}|. The |c| |l| etc cannot accept paragraphs. – yannisl Aug 14 '14 at 17:36
  • I see, that's great! Thanks for clarifying. – Abhimanyu Arora Aug 14 '14 at 17:56
8

Look at the listliketab package list columns

The following was posted on CTT a long time ago by Donald Arseneau for itemized and enumerated cells

\documentclass{article}
\usepackage{array}
\makeatletter
\newcolumntype{e}[1]{%--- Enumerated cells ---
   >{\minipage[t]{\linewidth}%
     \NoHyper%                Hyperref adds a vertical space
     \let\\\tabularnewline
     \enumerate
        \addtolength{\rightskip}{0pt plus 50pt}% for raggedright
        \setlength{\itemsep}{-\parsep}}%
   p{#1}%
   <{\@finalstrut\@arstrutbox\endenumerate
     \endNoHyper
     \endminipage}}

\newcolumntype{i}[1]{%--- Itemized cells ---
   >{\minipage[t]{\linewidth}%
        \let\\\tabularnewline
        \itemize
           \addtolength{\rightskip}{0pt plus 50pt}%
           \setlength{\itemsep}{-\parsep}}%
   p{#1}%
   <{\@finalstrut\@arstrutbox\enditemize\endminipage}}

\AtBeginDocument{%
    \@ifpackageloaded{hyperref}{}%
        {\let\NoHyper\relax\let\endNoHyper\relax}}
\makeatother
\begin{document}

\begin{tabular}[t]{|i{2.5cm}|e{3cm}|}
\hline
  \item Item A
  \item Item B   &
  \item Item 1
  \item Item 2   \\
\hline
\end{tabular}

\end{document} 
David Carlisle
  • 757,742
Danie Els
  • 19,694