Longtable 和 itemize - 删除垂直空间

Longtable 和 itemize - 删除垂直空间

我的表格目前如下所示:

在此处输入图片描述

这是代码:

\begin{longtable}{|P{7cm}|P{7cm}|}
    \caption{Test table} \\
    \hline

    \rowcolor{black} \textcolor{white}{\textbf{Column 1}} & \textcolor{white}{\textbf{Column 2}}  \\ \hline

    First Row & \vspace{-\baselineskip}
    \begin{itemize}[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
        \item Vans (last 2 months)
        \item Cars
        \item Trucks
        \item Planes
    \end{itemize} \\ \hline

    Second Row & \vspace{-\baselineskip}
    \begin{itemize}[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
        \item Apple (last 2 months)
        \item Banana
    \end{itemize} \\ \hline 

\end{longtable}

如何删除列表前后第 2 列的垂直空间?

谢谢。

答案1

由于不知道P列类型是什么,我将其替换为p。请注意,对于默认的布局来说,您的表格略微太宽了geometry

\documentclass[a4paper, 10pt]{article}
\usepackage[ showframe]{geometry}
\usepackage{longtable}
\usepackage{enumitem}
\usepackage[table]{xcolor}

\begin{document}

\begingroup
\setlist[itemize]{label={--},nosep, leftmargin=*, before=\vspace*{-\baselineskip}, after=\vspace*{-0.9\baselineskip}}
\setlength{\extrarowheight}{3pt}
\begin{longtable}{|p{7cm}| p{7cm}|}
\caption{Test table} \\
\hline
\rowcolor{black} \textcolor{white}{\textbf{Column 1}} & \textcolor{white}{\textbf{Column 2}} \\ \hline
\endfirsthead
\hline
\rowcolor{black} \textcolor{white}{\textbf{Column 1}} & \textcolor{white}{\textbf{Column 2}} \\ \hline
\endhead
First Row &
\begin{itemize}
\item Vans (last 2 months)
\item Cars
\item Trucks
\item Planes
\end{itemize}
\\
\hline
Second Row & %\vspace{-\baselineskip}
\begin{itemize}%[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
\item Apple (last 2 months)
\item Banana
\end{itemize} \\
\hline
\end{longtable}
\endgroup

\end{document} 

在此处输入图片描述

答案2

这是一个解决方案,通过将每个单元格放置在 中来在第二列中产生紧密的间距minipage

请注意,我还建议 (a) 不要使用任何垂直条和 (b) 使用较少但间距适当的水平条。

在此处输入图片描述

\documentclass{article}
\usepackage{geometry} % set page dimension parameters suitably
\usepackage{enumitem}
\usepackage{longtable}
\usepackage[table]{xcolor}
\newlist{myitemize}{itemize}{1}
\setlist[myitemize]{label={--},nosep,leftmargin=*}
\usepackage{array,ragged2e,booktabs}
\setlength\extrarowheight{2pt}

\begin{document}

\begin{longtable}{p{7cm}p{7cm}}
%% set up headers and footers
\caption{Test table} \label{tab:test} \\
\rowcolor{black} 
\textcolor{white}{\textbf{Column 1}} & 
\textcolor{white}{\textbf{Column 2}}  
\\ \addlinespace
\endfirsthead

\multicolumn{2}{l}{(Table \ref{tab:test}, cont'd)}\\
\addlinespace
\rowcolor{black} 
\textcolor{white}{\textbf{Column 1}} & 
\textcolor{white}{\textbf{Column 2}}  
\\ \addlinespace
\endhead

\midrule
\multicolumn{2}{r}{(continued on next page)}\\
\endfoot

\bottomrule
\endlastfoot

%% body of table
First Row & 
\begin{minipage}[t]{7cm} % same width as overall col. width
\RaggedRight % just an educated guess...
\begin{myitemize}
    \item Vans (last 2 months)
    \item Cars
    \item Trucks
    \item Planes
\end{myitemize} 
\end{minipage}\\ 
\addlinespace
Second Row & 
\begin{minipage}[t]{7cm}
\RaggedRight
\begin{myitemize}
    \item Apple (last 2 months)
    \item Banana \strut % "\strut": a typographic strut
\end{myitemize} 
\end{minipage}\\

\end{longtable}
\end{document}

相关内容