所以我有一个包含使用 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}