我有以下 LaTeX 代码
\newcolumntype{K}{>{\begin{minipage}[b]{21em}\begin{itemize}}c<{\end{itemize}\end{minipage}}}
%\newcolumntype{K}{>{\begin{minipage}[t]{21em}\begin{itemize}}c<{\end{itemize}\end{minipage}}}
\begin{tabular}{K K}\hline
\item Item 1-1 & \item Item 1-2 \tabularnewline\hline
\item Item 2-1 & \item Item 2-2 \tabularnewline\hline
\item Item 3-1 & \item Item 3-2 \tabularnewline\hline
\item Item 4-1 & \item Item 4-2 \tabularnewline\hline
\end{tabular}
水平线仅用于指示目的。如果小页面具有对齐说明符“b”或“c”,则表格行排版时不会有额外的垂直空间,即表格行之间的水平线直接附加到小页面的框上。
但我希望项目在顶部对齐。但是,如果我将对齐说明符更改为“t”(取消注释第二行),则每行顶部会突然插入一些额外的垂直空间。
为什么?我该如何避免这种情况?
答案1
\documentclass{article}
\usepackage{enumitem, ragged2e}
\usepackage[skip=1ex]{caption}
\usepackage{array}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\newcolumntype{K}[1]{ >{\RaggedRight\compress\itemize}p{#1}<{\enditemize}}
\newcommand*{\mcbf}[1]{\multicolumn{1}{>{\bfseries}c}{#1}}
\begin{document}
\begin{table}
\caption{table with special column}
\label{5.1}
\centering
\setlist[itemize]{nosep,%wide=0pt,
leftmargin=*,
after=\vspace*{-\dimexpr\baselineskip+\partopsep\relax}
}
\begin{tabular}{*{2}{K{12em}}}
\hline
\item Item 1-1 & \item Item 1-2 go here \tabularnewline \hline
\item Item 2-1 & \item Item 2-2 go here \tabularnewline \hline
\item Item 3-1 & \item Item 3-2 go here \tabularnewline \hline
\item Item 4-1 & \item Item 4-2 go here \tabularnewline \hline
\end{tabular}
\end{table}
\end{document}