2

I have trouble with enumerate items in tables. Please take a look below.

Although I've used to the enumitem package to eliminate all spaces around enumerate items, they make spacing when in a table.

How can I fix this?

\documentclass{article}
\RequirePackage{enumitem}
\setlist[enumerate]{
    itemsep=0pt,
    topsep=0pt,
    parsep=0pt,
}

\begin{document}

    \begin{tabular}{ | p{1\linewidth} |}
        \hline
        General paragraph\\
        \hline
    \end{tabular}

    \vspace{40pt}

    \begin{tabular}{ | p{1\linewidth} |}
        \hline
        \begin{enumerate}
            \item {} 
            Enumerate item
        \end{enumerate}\\
        \hline
    \end{tabular}

\end{document}

enter image description here

1
  • Additional space vertical space before and after list is defined by \topsep and partopsep. This space you can reduce or eliminate as it is suggested in received answers.
    – Zarko
    Nov 26, 2019 at 13:00

2 Answers 2

1

I'd recommend defining a new enumerate-like list for using in tabular and related environments. With the help of before and after you can remove the additional space around the item:

enter image description here

\documentclass{article}
\RequirePackage{enumitem}
\setlist[enumerate]{
    itemsep=0pt,
    topsep=0pt,
    parsep=0pt,
}

\newlist{tabenum}{enumerate}{1}
\setlist[tabenum]{wide=0pt, 
                  nosep, 
                  leftmargin= * ,
                  label*=\arabic*.,
                  after=\vspace{-\baselineskip},
                  before=\vspace{-0.6\baselineskip}}


\begin{document}

    \begin{tabular}{ | p{1\linewidth} |}
        \hline
        General paragraph\\
        \hline
    \end{tabular}

    \vspace{40pt}

    \begin{tabular}{ | p{1\linewidth} |}
        \hline
        \begin{tabenum}
            \item Enumerate item
        \end{tabenum}\\
        \hline
    \end{tabular}

\end{document}
1

A variant with etoolbox and a \compress command borrowed from an answer on this site.

Additionally, the width you chose for the p{..} column does not take into account the inter column spacing nor the vertical rules width, hence an overflow into into the right margin, as you can see from the first table:

\documentclass{article}

\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}
\usepackage{etoolbox}
\usepackage{enumitem}
\usepackage{array}
\setlength{\extrarowheight}{2pt}

\AtBeginEnvironment{tabular}{\setlist[enumerate]{label=(\arabic*), nosep, leftmargin =*, after=\vspace{-\baselineskip}}}

\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother

\begin{document}

        \noindent
    \begin{tabular}{ | p{1\linewidth} |}
        \hline
        General paragraph\\
        \hline
    \end{tabular}

    \vspace{40pt}
    \noindent
    \begin{tabular}{ |>{\compress\arraybackslash}p{\dimexpr1\linewidth-2\tabcolsep-2\arrayrulewidth} |}
        \hline
        \begin{enumerate}
            \item Enumerate item
            \item Another enumerate item
        \end{enumerate}\\
        \hline
    \end{tabular}

\end{document} 

enter image description here

You must log in to answer this question.

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