0

I have an itemize list inside a p table cell, and end up with unwanted vertical whitespace space before and after the list:

enter image description here

\documentclass{article}

\begin{document}
I don't want the extra vertical space preceding the bulleted list:
\begin{tabular}{p{4cm}p{4cm}}
   \begin{itemize}
   \item hello
   \end{itemize}
   &
   hello
\end{tabular}

I want something more like:
\begin{minipage}{4cm}
   \begin{itemize}
   \item hello
   \end{itemize}
\end{minipage}
%
\begin{minipage}{4cm}
   hello
\end{minipage}
\end{document}

What's the simplest/most idiomatic way to avoid this?

Edit: prepending the itemize environment with \vspace{-\baselineskip} works. Is this the best way to do it?

3
  • see tex.stackexchange.com/questions/501182/…
    – Zarko
    Dec 12 '19 at 17:10
  • Thanks - didn’t find that one (tabular vs tabularx, I guess). Renamed my question to make the connection more explicit.
    – Roly
    Dec 12 '19 at 17:20
  • In the given link is not the point tabularx but definition of column type. It can be p{...} too! I will show you in my answer (asap)!
    – Zarko
    Dec 12 '19 at 18:41
1

if only the top vertical space is mater of concern, than solution provided by Ulrike 's answer can help you:

enter image description here

\documentclass{article}
\usepackage{array}

\begin{document}
I don't want the extra vertical space preceding the bulleted list:

\begin{tabular}{>{\csname @minipagetrue\endcsname}p{4cm}p{4cm}} % insert minipages in cells
\hline  % for seeing the top tables's border
   \begin{itemize}
   \item hello
   \item hello also in the next item
   \end{itemize}
   &    hello   \\
\hline
\end{tabular}
\end{document}

However, if you like to control more attributes of list in table, than you can do this by use of enumitem package and define new list, for example tabitem:

\documentclass{article}
\usepackage{array}
\usepackage{enumitem}       
\newlist{tabitem}{itemize}{1}% <-- defined new list for use in tables
\setlist[tabitem]{nosep,     % <-- new list setup
                  leftmargin = *         ,
                  label      = $\bullet$ ,
                  after      = \vspace{-\baselineskip}
                     }

\begin{document}
I don't want the extra vertical space preceding the bulleted list:

\begin{tabular}{>{\csname @minipagetrue\endcsname}p{4cm}p{4cm}} % insert minipages in cells
\hline  % for seeing the top tables's border
   \begin{tabitem}
   \item hello
   \item hello also in the next item where is no space after end of list
   \end{tabitem}
   &    hello   \\
\hline
\end{tabular}
\end{document}

It may be handy, if you define new column type, for example

\newcolumntype{P}[1]{>{\csname @minipagetrue\endcsname\RaggedRight}p{#1}}

and than write:

\documentclass{article}
\usepackage{array}
\usepackage{enumitem}       
\newlist{tabitem}{itemize}{1}% <-- defined new list for use in tables
\setlist[tabitem]{nosep,     % <-- new list setup
                  wide=0pt,  % <-- new "makeup" for list formatting
                             % see @Bernard's comment below
                  label      = $\bullet$ ,
                  after      = \vspace{-\baselineskip}
                     }
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\csname @minipagetrue\endcsname\RaggedRight}p{#1}}
\begin{document}
I don't want the extra vertical space preceding the bulleted list:

\begin{tabular}{P{4cm}p{4cm}} % insert minipages in cells
\hline  % for seeing the top tables's border
   \begin{tabitem}
   \item hello
   \item hello also in the next item where is no space after end of list
   \end{tabitem}
   &    hello   \\
\hline
\end{tabular}
\end{document}

where is also considered @Bernard comment regarding list formatting. Above MWE (Minimal Working Example) gives:

enter image description here

Note: definition

\newcolumntype{P}[1]{>{\csname @minipagetrue\endcsname}p{#1}}

is equivalent to definition:

\makeatletter
\newcolumntype{P}[1]{>{\@minipagetrue\RaggedRight}p{#1}}
\makeatother
2
  • Bernard, you are right. I was to much focused on vertical spaces :-(. I will add this possibilities to last example in answer (asap).
    – Zarko
    Dec 12 '19 at 19:10
  • Thanks - I hadn’t noticed the additional trailing space, but on closer inspection I see it in my table, so this is my preferred answer.
    – Roly
    Dec 12 '19 at 19:19
1

The simplest and most effective way to avoid the extra space, is to redirect a @minipagetrue into the column by defining a special column, as demonstrated by @egreg in this answer. I.e. you load the package array, define a new column type using redirection. Of course you may add other commands to the redirection, for example alignment, font attributes, etc.

enter image description here

\documentclass{article}

\usepackage{array}
\usepackage{enumitem}
\makeatletter
\newcolumntype{P}[1]{>{\@minipagetrue}p{#1}}
\makeatother

\begin{document}
I don't want the extra vertical space preceding the bulleted list:

\begin{tabular}{P{4cm}p{4cm}}
   \begin{itemize}
   \item hello
   \end{itemize}
   &
   hello
\end{tabular}

I want something more like:

\begin{minipage}{4cm}
   \begin{itemize}
   \item hello
   \end{itemize}
\end{minipage}
%
\begin{minipage}{4cm}
   hello
\end{minipage}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.