使用 tabularx 中的列表减少单元格中的填充

使用 tabularx 中的列表减少单元格中的填充

所以我有一个包含使用 tabularx 编写的列表的表格,但是列表的顶部和左侧有多余的填充。有没有办法只针对这个表格的空间减少这些填充?

代码:

% PRO CON TABLE FOR DIFFERENT TOOLKITS
\begin{table}[h]
\centering
\begin{tabularx}{\textwidth}{|c|X|X|}
\hline
\textbf{Name} & \textbf{Advantages} & \textbf{Disadvantages} \\
\hline
QuTiP &
\begin{itemize}
\item Supervisor is one of the lead developers on the project, so can ask questions and get advice as needed.
\item Widely used, with 371 citations at time of writing, meaning tool may have more value
\end{itemize} & 
\begin{itemize}
\item Con
\item Con
\end{itemize}
\\
\hline
(... other lines ...)
\end{tabularx}%
\end{table}

单元格填充过多的表格示例

答案1

在该包的帮助下,enumitem我创建了一个新的itemize环境,用于表格单元格:

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx}
\usepackage{enumitem}

\newlist{tabitemize}{itemize}{1}

\setlist[tabitemize]{nosep,
                  topsep= 0pt,
                  partopsep=0pt,
                  leftmargin= *,
                  label=\textbullet,
                  before=\vspace{-0.6\baselineskip},
                  after=\vspace{-\baselineskip}
                  }

\begin{document}

% PRO CON TABLE FOR DIFFERENT TOOLKITS
\begin{table}[h]
\centering
\begin{tabularx}{\textwidth}{|c|X|X|}
\hline
\textbf{Name} & \textbf{Advantages} & \textbf{Disadvantages} \\
\hline
QuTiP &
\begin{tabitemize}
\item Supervisor is one of the lead developers on the project, so can ask questions and get advice as needed.
\item Widely used, with 371 citations at time of writing, meaning tool may have more value
\end{tabitemize} & 
\begin{tabitemize}
\item Con
\item Con
\end{tabitemize}
\\
\hline
(... other lines ...)
\end{tabularx}%
\end{table}

\end{document}

答案2

另一种解决方案是使用enumitem在此站点上找到的宏:

\documentclass{article}
\usepackage{tabularx}
\usepackage{enumitem}

    \makeatletter
    \newcommand*{\compress}{\@minipagetrue}
    \makeatother

\begin{document}%, after=\vspace*{-5\topsep}

% PRO CON TABLE FOR DIFFERENT TOOLKITS
\begin{table}[h]
\centering\sffamily\setlength{\extrarowheight}{4pt}
\setlist[itemize]{wide=0pt, topsep=0pt, leftmargin=*, after ={\vspace*{\dimexpr-\baselineskip + \partopsep}}}
\begin{tabularx}{\textwidth}{|c|*{2}{>{\compress}X|}}
\hline
\textbf{Name} & \textbf{Advantages} & \textbf{Disadvantages} \\ \hline
QuTiP &
\begin{itemize}
\item Supervisor is one of the lead developers on the project, so can ask questions and get advice as needed.
\item Widely used, with 371 citations at time of writing, meaning tool may have more value
\end{itemize} &
\begin{itemize}
\item Con
\item Con
\end{itemize}
\\\hline
(... other lines ...)
\end{tabularx}%
\end{table}

\end{document} 

在此处输入图片描述

相关内容