3

How can I insert a numbered list inside a table cell?

I want to show a comparison between two different procedures and how they alter a set of sequences.

1
  • 2
    Cells had to be type of parbox, i.e. p{...} or X from tabularx, than use itemize environment. issues about vertical spaces can be elegant solved with used of enumitem package. If you will provide, what you try so far, we can help you where you stuck.
    – Zarko
    Feb 7, 2017 at 18:24

2 Answers 2

5

You can use either a p{} type column or just insert parboxes around.

Option 1:

option1

\documentclass{article}
\usepackage{booktabs}

\begin{document}
    \begin{tabular}{p{.45\textwidth}p{.45\textwidth}}
        \toprule Head & Head\\\midrule
        \begin{enumerate}
            \item Test
            \item Second
        \end{enumerate} & \begin{enumerate}
            \item Test
            \item Second
            \item Third
        \end{enumerate}\\\bottomrule
    \end{tabular}
\end{document}

Option 2:

option2

\documentclass{article}
\usepackage{booktabs}

\begin{document}
    \begin{tabular}{ll}
        \toprule Head & Head\\\midrule
        \parbox{.45\textwidth}{\begin{enumerate}
            \item Test
            \item Second
        \end{enumerate}} & \parbox{.45\textwidth}{\begin{enumerate}
            \item Test
            \item Second
            \item Third
        \end{enumerate}}\\\bottomrule
    \end{tabular}
\end{document}
1
  • Further comment: You can use the enumitem package and then use the leftmargin=* option to remove the space left of the environments. That's one of the aspects Bernard mentioned in his answer.
    – TeXnician
    Jun 8, 2018 at 15:48
4

Here are some improvements, with tabularx,enumitem and makecell:

\documentclass{article}
\usepackage{booktabs}
\usepackage{enumitem}
\usepackage{tabularx, makecell}%
\renewcommand\theadfont{\normalsize\bfseries}
        \usepackage{etoolbox} %
        \AtBeginEnvironment{tabularx}{\setlist[enumerate, 1]{wide, leftmargin=*, itemsep=0pt, before=\vspace{-\dimexpr\baselineskip +2 \partopsep}, after=\vspace{-\baselineskip}}}

\begin{document}
    \begin{tabularx}{\linewidth}{XX}
        \toprule %
        \thead{Head} & \thead{Head}\\%
        \cmidrule[\lightrulewidth](lr){1-2}
        \begin{enumerate}
            \item Test
            \item Second
        \end{enumerate} & \begin{enumerate}%
            \item Test
            \item Second
            \item Third
        \end{enumerate}\\%
        \bottomrule
    \end{tabularx}

\end{document} 

enter image description here

7
  • Thanks. What are the improvements here? Feb 8, 2017 at 8:10
  • 1
    @drozzy The improvements are less space at top and bottom as well as the omitted indentation on the left side.
    – TeXnician
    Feb 8, 2017 at 8:25
  • It still looks a bit weird. In particular, the mid line is shorter than the outer two lines. Feb 8, 2017 at 19:10
  • It is on purpose (obtained with (lr) in the code). I think it looks nicer, but if you don't want it, replace\cmidrule[\lightrulewidth](lr){1-2} with a plain \midrule.
    – Bernard
    Feb 8, 2017 at 19:24
  • @Bernard Please find the code snippet here. I only want some changes in the second column of second and third row. I want to use enumerate lists there to have a left margin for the extra long lines. How do I achieve that keeping all the formatting options existing already in the table? PS: \rownum is a row counter defined earlier. Jan 9, 2021 at 18:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .