![使用 tabularx 中的列表减少单元格中的填充](https://linux22.com/image/394358/%E4%BD%BF%E7%94%A8%20tabularx%20%E4%B8%AD%E7%9A%84%E5%88%97%E8%A1%A8%E5%87%8F%E5%B0%91%E5%8D%95%E5%85%83%E6%A0%BC%E4%B8%AD%E7%9A%84%E5%A1%AB%E5%85%85.png)
所以我有一个包含使用 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}