Spacing issues with itemize in a table

I've been trying to use lists of items in a table. This was easy to do but I could not find a way to align them in the same way as plain text in a table. Let me give an example:

\documentclass{article}

\usepackage{paralist}

\begin{document}

\begin{tabular}{|p{2cm}|p{10cm}|}
\hline
Blah blah &
\begin{compactitem}
\item First
\item Second
\end{compactitem} \\
\hline
\end{tabular}

\end{document}


Instead of just itemize I used paralist so the list gets more compact, however there is still a lot of space added before and after the list. The result looks pretty awful, I would like to have the same spacing around "Blah Blah" as I have around the items in the right cell.

I've also found some tricks to reduce the space to the upper or lower \hline of the cell, but none of these could match the alignment with just plain text.

-
Here's a solution which also provides an explanation for using \@minipagetrue: Preventing itemize environment to insert initial vertical space. Also, this question is about the very same problem: Including an itemized list within a tabular column using the paralist package. –  Stefan Kottwitz Mar 9 '11 at 18:56

Herbert is right on with \@minipagetrue removing the space at the top, but the cleanest way I've found to remove the space at both the bottom and the top is with an actual minipage environment.

I'm going to use enumitem with nosep instead of instead of paralist and its compactitem because I want to use enumitem's after option.

\documentclass{article}

\usepackage{enumitem}

\begin{document}

\begin{tabular}{|p{2cm}|p{10cm}|}
\hline
Blah blah &
\begin{minipage}[t]{\linewidth}
\begin{itemize}[nosep,after=\strut]
\item First
\item Second
\end{itemize}
\end{minipage} \\
\hline
\end{tabular}

\end{document}


Result:

Note that I've experienced cases where the after=\strut actually adds unnecessary space below the list. If you run into that, try just taking the strut out entirely and see if it lays out OK.

Further notes:

• Can't/don't want to specify the maximum width on that minipage? Try varwidth instead, which will shrink the box horizontally if possible:

% Preamble:
\usepackage{varwidth}
% ...then, instead of minipage, use varwidth...
\begin{varwidth}[t]{\linewidth}
\begin{itemize}[nosep,after=\strut]
\item First
\item Second
\end{itemize}
\end{varwidth} \\

• You can use enumitem's \newlist if you don't want to type that \begin{itemize}[nosep,after=\strut] over and over. For example:

% Preamble:
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{label=\textbullet,nosep,after=\strut}
% ...then, in your table cell...
\begin{minipage}[t]{\linewidth}
\begin{tabitemze}
\item First
\item Second
\end{tabitemize}
\end{minipage} \\

• If you intend to do this a lot in a column of a table, this answer shows how to create a compact list column type. (Donald Arseneau's solution there was key to me figuring out to do \strut.)

• In case you're interested, the comments in this answer explain why minipage gets rid of the space at the top.

-
Note: I had problems with nosep. Said it wasn't defined. I use noitemsep. Also I had to insert \vspace{-2mm} after the minipage-definition, since hyperref stupidly adds some space there. Also, it took me almost a whole day to find this solution. Exactly what I was searching, I can't believe this is not highly uprated. You, sir, deserve a medal. –  albifant Feb 5 at 15:34
\documentclass{article}

\usepackage{paralist,array}
\makeatletter\let\MPtrue\@minipagetrue\makeatother

\begin{document}

\begin{tabular}{|p{2cm}|p{10cm}|}
\hline
Blah blah & \MPtrue
\begin{compactitem}
\item First
\item Second
\end{compactitem} \\\hline
\end{tabular}

\end{document}

-
I don't need array for that, right? Also I do not understand what's the deal with minipage? Thx for the answer! –  Nils Mar 9 '11 at 15:24
@Nils: yes, I had before >{\MPtrue}p{10cm} and then forgot to delete array. –  Herbert Mar 9 '11 at 15:27
So the idea is basically to add \MPtrue to every cell which has items in it? I get very strange results with this, sometimes it appears not to work at all.. –  Nils Mar 9 '11 at 15:30
@Nils: give an example where it does not work! –  Herbert Mar 9 '11 at 15:32
Can't really reproduce it.. it seems to work for simple examples.. but it only removes the space before compactitem.. it's just another hack and not a real solution :( –  Nils Mar 9 '11 at 15:42
show 1 more comment

You could also use enumitem package. Using it you can access various useful settings as key-value pairs:

\usepackage{enumitem}
\begin{document}

\begin{tabular}{|p{2cm}|p{10cm}|}
\hline
Blah blah & \begin{itemize}[topsep=-0.5cm]\item First \item Second \end{itemize} \\
\hline
\end{tabular}
\end{document}


If that is not enough, you can manually kill space with \vspace*{-1.5mm}. Asterix ensures the space is added (in this case, because the number is negative, removed).

\documentclass[a4paper]{article}

\usepackage{enumitem}
\begin{document}

\begin{tabular}{|p{2cm}|p{10cm}|}
\hline
Blah blah & \vspace*{-0.2cm}\begin{itemize}[topsep=-0.5cm,leftmargin=0.3cm]\item a \item b \end{itemize}\\
\hline
\end{tabular}

\end{document}


Both the answer and the result seem very ugly to me.

-