我正在制作一个表格,其中两列构成优点/缺点列表。为此,我创建了一个自定义列表环境,其周围留有最小的空白。但是,我仍然发现列表顶部的显示略低于其左侧“方法”列中相应的正常文本。根据图表这里,我认为这可以完成\topsep=0em \parsep=0em \partopsep=0em
但仍然留下垂直不连续性。
下面是我当前所在位置的 MWE 示例以及输出。有人能告诉我如何修改它以垂直对齐列表文本和普通文本的顶部吗,例如将“一个缺点”与“第一个方法名称”对齐,“好结果”与“第二个方法”对齐。
\documentclass[12pt, oneside]{report}
\renewcommand{\baselinestretch}{1.2}
\usepackage[letterpaper,includehead,left=3.25cm,right=2.5cm,top=2.5cm,headsep=1.5cm,headheight=0.0cm,bottom=2.5cm,footskip=1.0cm]{geometry}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{array}
\newenvironment{compactlist}{ % List with minimal white space to fit in small areas, e.g. table cell
\begin{list}{$\bullet$}{\leftmargin=0.5em \rightmargin=0em \topsep=0em \parskip=0em \parsep=0em \listparindent=0em \partopsep=0em \itemsep=0pt \itemindent=0em \labelwidth=\leftmargin\labelsep+0.25em}
}{
\end{list}
}
\begin{document}
\begin{table}[htpb]
\centering
\footnotesize
\begin{tabular}{ p{2cm} | p{3cm} | p{4cm} | p{4cm}}
\toprule
\cmidrule(r){1-2}
\centering \textbf{Class} & \textbf{Method} & \textbf{Pros} & \textbf{Cons} \\
\midrule
\multirow{2}{*}{\begin{minipage}[c]{\linewidth}\centering \textbf{Class 1 name}\end{minipage}}
& First method name with linebreak
& \begin{compactlist}
\item One downside
\end{compactlist}
& \begin{compactlist}
\item Another downside with longer text to create a linebreak or two
\end{compactlist} \\
& Second method
& \begin{compactlist}
\item Good results
\item Fast
\end{compactlist}
& \begin{compactlist}
\item Expensive
\end{compactlist} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
您应该将列表括在\minipage
:
\newenvironment{compactlist}{ % List with minimal white space to fit in small areas, e.g. table cell
\begin{minipage}{\linewidth}\begin{list}{$\bullet$}{\leftmargin=0.5em \rightmargin=0em \topsep=0em \parskip=0em \parsep=0em \listparindent=0em \partopsep=0em \itemsep=0pt \itemindent=0em \labelwidth=\leftmargin\labelsep+0.25em}
}{
\end{list}\end{minipage}
}
如果您包含[t]
可选参数,则会\begin{minipage}[t]{\linewidth}
得到:
更新:正如 OP 所评论的那样,第一列的数据略低于应有的位置。解决该问题的一种方法是使用[t]
上面提到的选项以及:
\multirow{2}{*}{\begin{minipage}[c]{\linewidth}\centering \textbf{Class 1 name}\end{minipage}}
完整代码如下:
\documentclass[12pt, oneside]{report}
\renewcommand{\baselinestretch}{1.2}
\usepackage[letterpaper,includehead,left=3.25cm,right=2.5cm,top=2.5cm,headsep=1.5cm,headheight=0.0cm,bottom=2.5cm,footskip=1.0cm]{geometry}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{array}
\newenvironment{compactlist}{ % List with minimal white space to fit in small areas, e.g. table cell
\begin{minipage}[t]{\linewidth}\begin{list}{$\bullet$}{\leftmargin=0.5em \rightmargin=0em \topsep=0em \parskip=0em \parsep=0em \listparindent=0em \partopsep=0em \itemsep=0pt \itemindent=0em \labelwidth=\leftmargin\labelsep+0.25em}
}{
\end{list}\end{minipage}
}
\begin{document}
\begin{table}[htpb]
\centering
\footnotesize
\begin{tabular}{ p{2cm} | p{3cm} | p{4cm} | p{4cm}}
\toprule
\cmidrule(r){1-2}
\centering \textbf{Class} & \textbf{Method} & \textbf{Pros} & \textbf{Cons} \\
\midrule
\multirow{2}{*}{\begin{minipage}[c]{\linewidth}\centering \textbf{Class 1 name}\end{minipage}}
& First method name with linebreak
& \begin{compactlist}
\item One downside
\end{compactlist}
& \begin{compactlist}
\item Another downside with longer text to create a linebreak or two
\end{compactlist} \\
& Second method
& \begin{compactlist}
\item Good results
\item Fast
\end{compactlist}
& \begin{compactlist}
\item Expensive
\end{compactlist} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
另一种选择是将列表内容括在内\parbox
,但我认为\minipage
解决方案更简单。