14

Consider

\documentclass{article} \usepackage{enumitem} \begin{document} \begin{tabular}{l p{4cm}} Head & Content\\ \hline Foo & \begin{enumerate}[label={\textbf{\arabic*.}}, itemindent=0pt, leftmargin=*, nosep] \item A \item B \end{enumerate} \\ \hline \end{tabular} \end{document} 

which produces unwanted vertical space before and after the list:

enter image description here

However adding surrounding text renders as expected:

\begin{tabular}{l p{4cm}} Head & Content\\ \hline Foo & How does \begin{enumerate}[label={\textbf{\arabic*.}}, itemindent=0pt, leftmargin=*, nosep] \item A \item B \end{enumerate} this work? \\ \hline \end{tabular} 

enter image description here

1
  • 1
    Technically, lists use \ifvmode to detect when they are inside a paragraph or between paragraphs (and add extra space). Commented Jul 28, 2018 at 12:52

2 Answers 2

10

Maybe it's simpler to define a variant of enumerate for use in tables, with specific parameters. I borrowed the \compress command from an answer on this site: it makes latex believe the list is at the very beginning of a minipage, so latex adds no vertical spacing before lists.

I also used the rules from booktabs, which have some vertical padding, and a variable thickness.

\documentclass{article} \usepackage{enumitem} \newlist{tabenum}{enumerate}{1} \setlist[tabenum]{label=\arabic*. ,wide=0pt, leftmargin=*, nosep, itemsep=2pt, font = \bfseries, after=\vspace{-\baselineskip}, before=\compress} \usepackage{array, booktabs} \makeatletter \newcommand*{\compress}{\@minipagetrue} \makeatother \begin{document} \begin{tabular}{l p{4cm}} Head & Content\\ \midrule Foo & \begin{tabenum} \item A. Some text some text some text \item B \end{tabenum} \\ \bottomrule \end{tabular} \end{document} 

enter image description here

3
  • 2
    You can add the \compress with before=\compress to the list settings. Commented Jul 28, 2018 at 13:30
  • Excellent suggestion, Ulrike! I've incorporated to the code. Thanks:-) Commented Jul 28, 2018 at 13:38
  • Thanks for the idea! While this does solve the problem with vertical space before the enum, space afterwards is not dynamically calculated. Appended text will be placed ‘inside’ the enumeration. Commented Jul 28, 2018 at 16:44
4

You can use the before and after options in order to adjust the space before and after the list to your needs:

enter image description here

\documentclass{article} \usepackage{enumitem} \begin{document} \begin{tabular}{l p{4cm}} Head & Content\\ \hline Foo & \begin{enumerate}[label={\textbf{\arabic*.}}, itemindent=0pt, leftmargin=*, nosep,after=\vspace{-\baselineskip},before=\vspace{-0.5\baselineskip}] \item A \item B \end{enumerate} \\ \hline \end{tabular} \end{document} 
1
  • That sure is a solution, but also hard coded. Is there a flexible solution? I thought enumitem could handle this situation. Commented Jul 28, 2018 at 13:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.