表格中逐项列出:项目周围出现虚假垂直空白

表格中逐项列出:项目周围出现虚假垂直空白

我在表格单元格itemize内有一个列表p,列表前后出现了不需要的垂直空白:

在此处输入图片描述

\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}

避免这种情况的最简单/最惯用的方法是什么?

编辑:itemize环境添加\vspace{-\baselineskip}作品。这是最好的方法吗?

答案1

如果只关注顶部垂直空间,则解决方案为乌尔里克的回答能帮到你:

在此处输入图片描述

\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}

但是,如果您想控制表中列表的更多属性,那么您可以使用enumitem包并定义新列表来实现,例如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}

例如,如果您定义新的列类型,这可能会很方便

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

然后写道:

\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}

其中也被认为是@Bernard 关于列表格式的评论。上面的 MWE(最小工作示例)给出:

在此处输入图片描述

注意:定义

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

等同于定义:

\makeatletter
\newcolumntype{P}[1]{>{\@minipagetrue\RaggedRight}p{#1}}
\makeatother

答案2

避免多余空间的最简单、最有效的方法是通过定义特殊列将@minipagetrue 重定向到列中,如@egreg 所示这个答案. 即你加载包大批,使用重定向定义新的列类型。当然,您可以向重定向添加其他命令,例如对齐、字体属性等。

在此处输入图片描述

\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}

相关内容