# Enumerate in tabular creates unwanted vertical space

Consider

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\begin{tabular}{l p{4cm}}
\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:

However adding surrounding text renders as expected:

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


• Technically, lists use \ifvmode to detect when they are inside a paragraph or between paragraphs (and add extra space). – John Kormylo Jul 28 '18 at 12:52

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}}
\midrule
Foo &
\begin{tabenum}
\item A. Some text some text some text
\item B
\end{tabenum}
\\
\bottomrule
\end{tabular}

\end{document}


• You can add the \compress with before=\compress to the list settings. – Ulrike Fischer Jul 28 '18 at 13:30
• Excellent suggestion, Ulrike! I've incorporated to the code. Thanks:-) – Bernard Jul 28 '18 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. – qwertz Jul 28 '18 at 16:44

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

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\begin{tabular}{l p{4cm}}

• That sure is a solution, but also hard coded. Is there a flexible solution? I thought enumitem could handle this situation. – qwertz Jul 28 '18 at 13:11