我有一个表格内的项目符号列表,但列表上方有多余的空白,导致其与行中的其他单元格水平不对齐。列表开头为\begin{itemize}[noitemsep,topsep=0pt]
有一点帮助,但问题仍然存在。 有没有办法摆脱这个空间?
下面是我的最小工作示例,由以下 4 种代码模式组合组成上面的链接:
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{enumitem}
\begin{document}
Hello world.
\begin{tabular}{l>{\raggedright}p{3in}}
\toprule
Item title \#1
&
\begin{itemize}[noitemsep,topsep=0pt] % Code pattern 1
\item Two
\item bullets
\end{itemize}
\tabularnewline[0.1in]
Item title \#2
&
\begin{itemize}[noitemsep,topsep=0pt] % Code pattern 1, 2nd row
\item Two more
\item bullets
\end{itemize}
\tabularnewline[0.1in]
Item title \#3
&
\kern-\parskip\begin{itemize}[noitemsep,topsep=0pt] % Code pattern 2
\item Another two
\item bullets
\end{itemize}\kern-\parskip
\tabularnewline[0.1in]
Item title \#4
&
\kern-\parskip\begin{itemize} % Code pattern 3
\item Another two more
\item bullets
\end{itemize}\kern-\parskip
\tabularnewline[0.1in]
Item title \#5
&
\begin{itemize}[noitemsep,topsep=-8pt] % Code pattern 4
\item Another two more
\item bullets still
\end{itemize}
\tabularnewline \bottomrule
\end{tabular}
\end{document}
编译结果如下:
答案1
还有一个更简单的没有列表的表格吗?
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\newcommand\xxx{\par\hangindent1em\makebox[1em][l]{$\bullet$}}
\begin{tabular}{lp{2in}}\toprule
Item title \#1 & \xxx Two \xxx bullets \\\addlinespace
Item title \#2 & \xxx Two more \xxx bullets \\\addlinespace
Item title \#3 & \xxx Another two \xxx bullets \\\addlinespace
Item title \#4 & \xxx Another two more \xxx bullets \\\addlinespace
Item title \#5 & \xxx Another two more \xxx bullets with a long item taking more than one line. \\\bottomrule
\end{tabular}
\end{document}
答案2
只需添加
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{label=\textbullet,
leftmargin=*,
nosep,
before=\begin{minipage}[t]{\hsize}\raggedright,
after=\end{minipage}}
到你的序言中并使用tabitemize
代替itemize
。不再需要手动调整:
在下面的 MWE 中,我也用 替换了>{\raggedright}
。>{\raggedright\arraybackslash}
使用此修改后的代码,您可以使用常规\\
代替tabularnewline
。
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{enumitem}
%%% added:
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{label=\textbullet,
leftmargin=*,
nosep,
before=\begin{minipage}[t]{\hsize}\raggedright,
after=\end{minipage}}
\begin{document}
\begin{tabular}{l>{\raggedright\arraybackslash}p{3in}}
\toprule
Item title \#1
&
\begin{tabitemize}
\item Two
\item bullets
\end{tabitemize}\\
Item title \#2
&
\begin{tabitemize}
\item Two more
\item bullets
\end{tabitemize}\\
\bottomrule
\end{tabular}
\end{document}
答案3
我使用相关参数定义了一种新的列表类型,并使用了一个compress
命令(借用自该站点的一个答案),使 Latex 相信列表位于小页面的开头。
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{enumitem}
\makeatletter
\newcommand{\compress}{\@minipagetrue}
\makeatother
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize,1]{noitemsep, label=\textbullet, topsep=0pt, after=\vspace{-\baselineskip}}
\begin{document}
Hello world.\bigskip
\begin{tabular}{l>{\raggedright\compress}p{3in}}
\toprule
Item title \#1
& \begin{tabitemize}
\item Two
\item bullets
\end{tabitemize}
\tabularnewline[0.1in]
Item title \#2
& \begin{tabitemize}
\item Two more
\item bullets
\end{tabitemize}
\tabularnewline[0.1in]
Item title \#3
& \begin{tabitemize}
\item Another two
\item bullets
\end{tabitemize}
\tabularnewline[0.1in]
Item title \#4
& \begin{tabitemize}
\item Another two more
\item bullets
\end{tabitemize}\kern-\parskip
\tabularnewline[0.1in]
Item title \#5
& \begin{tabitemize}
\item Another two more
\item bullets still
\end{tabitemize}
\tabularnewline \bottomrule
\end{tabular}
\end{document}
答案4
谢谢利安德里斯,我找到了这一页
并通过一些实验找到了答案:
\vspace{-1em}\begin{itemize}[noitemsep,topsep=0pt]
。
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{enumitem}
\begin{document}
Hello world.
\begin{tabular}{l>{\raggedright}p{3in}}
\toprule
Item title \#1
&
\vspace{-1em}\begin{itemize}[noitemsep,topsep=0pt] % Code pattern 1
\item Two
\item bullets
\end{itemize}
\tabularnewline[0.1in]
Item title \#2
&
\vspace{-1em}\begin{itemize}[noitemsep,topsep=0pt] % Code pattern 1, 2nd row
\item Two more
\item bullets
\end{itemize}
\vspace{-1em} \tabularnewline \bottomrule
\end{tabular}
\end{document}
编译结果如下:
不幸的是,\vspace{-1em} \tabularnewline \bottomrule
没有消除底部的空间,并\tabularnewline \vspace{-1em} \bottomrule
生成错误。我可以忍受。