4

I want to have nice tight lists with no spacing before, after or in-between the items. I managed to do this according to the answer from this question: How to remove the whitespace BEFORE itemize/enumerate?

\usepackage{enumitem}
\setlist{nosep}

This works fine when a list comes before and/or after a paragraph.

BUT: This doesn't work in a tabular environment. There is some extra vertical space before and after the list. Can somebody tell me why and more importantly how to fix it?

Thank you in advance for your help.

ExtraSpaceInTables

The problem can be reproduced using this code:

\documentclass{article}

\usepackage{enumitem}
\setlist{nosep,noitemsep }

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea 
\begin{itemize}
\item Item 1
\item Item 2
\end{itemize}
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,     
\begin{table}[h]
\begin{tabular}{|p{1\textwidth}|}\hline
\begin{itemize}[itemparsep=0pt]
\item Item 1
\item Item 2
\end{itemize}\\
\hline
\end{tabular}
\end{table} 

\end{document}
1
  • 1
    Why? Because look better that without spaces ...
    – Fran
    Commented Dec 4, 2018 at 17:11

3 Answers 3

3

The following code makes latex believe the list is in a minipage, so it adds no vertical space. At the end of the list, it adds a negative vertical space:

\documentclass{article}
\usepackage{array}
\usepackage{enumitem}
\setlist{nosep, noitemsep }
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
\begin{itemize}
\item Item 1
\item Item 2
\end{itemize}
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,     
\begin{table}[h]
\begin{tabular}{|>{\compress}p{1\textwidth}|}\hline
\begin{itemize}[parsep=0pt, after=\vspace*{-\baselineskip}]
\item Item 1
\item Item 2
\end{itemize}\\
\hline
\end{tabular}
\end{table}

\end{document} 

enter image description here

2

It is simpler to use a minipage directly, only [after=\strut] option is needed because the space after itemize is also removed.

\documentclass{article}    
\usepackage{enumitem}
\setlist{nosep }

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea 
\begin{itemize}
  \item Item 1
  \item Item 2
\end{itemize}
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,     
\begin{table}[h]
\begin{tabular}{|p{\textwidth}|}\hline
  \begin{minipage}[t]{\linewidth}
    \begin{itemize}[after=\strut]
      \item Item 1
      \item Item 2
    \end{itemize}
  \end{minipage}\\
  \hline
\end{tabular}
\end{table} 

\end{document}

enter image description here

0
1

Other ways to have well fenced and cramped list without too much effort:

What about a \vbox?

\documentclass{article}
\usepackage{enumitem}\setlist{nosep,noitemsep}
\begin{document}
\noindent\fbox{\vbox{\begin{itemize}
\item Item 1    
\item Item 1    
\end{itemize}}}

Or a minipage, without tabular:

\documentclass{article}
\usepackage{enumitem}\setlist{noitemsep}
\begin{document}
\noindent\fboxsep2pt\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule}
\begin{itemize}
\item Item 1    
\item Item 1    
\end{itemize}
\end{minipage}}
\end{document}

Or a "list like a tabular" (or the opposite, not sure...):

\documentclass{article}
\usepackage{listliketab,array}
\usepackage{tabularx}
\begin{document}
\storestyleof{itemize}
\begin{listliketab}
\renewcommand\arraystretch{1} % is not better the default?
\begin{tabularx}{\linewidth}{|LX|}\hline
\textbullet & Item 1 \\
\textbullet & Item 2 \\\hline
\end{tabularx}
\end{listliketab}
\end{document}
1
  • Thank you for the reply. Maybe my example was a bit too short. I need more than just the box around the list but actually a real table. In the final version, there are going to be multiple columns and rows.But with the answer from @AboAmmar I am good to go.
    – Nick
    Commented Dec 9, 2018 at 15:13

You must log in to answer this question.

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