我无法让多行列中的文本垂直对齐到中心。
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{table}
\centering
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\begin{tabular}{c c c c}
\toprule
\multicolumn{3}{c}{\bfseries Heading 1}
& \bfseries Heading 2
\\
\cmidrule(r){1-3}
\cmidrule(l){4-4}
l
& \multicolumn{1}{m{8em}}{
or,
em,
ip,
su,
md,
ol,
or,
si,
ta,
m,
e
}
& \multirow{2}{*}{t}
& \multicolumn{1}{m{8em}}{%
\multirow{2}{=}{%
con,
sec,
tet,
ur,
ad,
ip,
is,
ci,
ng,
e,
l,
i,
t
}}
\\
\cmidrule{1-2}
n
& \multicolumn{1}{m{8em}}{%
un,
ca,
ts,
em,
se,
do,
rc,
ib,
la,
nd,
it
}
& % t
& % <Heading 2>
\\
\bottomrule
\end{tabular}
\label{tab:table1}
\end{table}
\end{document}
该表的第 3 列和第 4 列应垂直对齐在中心,但未出现相当是。相反,它稍微移到了顶部。当我使用 minipage 而不是多列覆盖单列时,也会发生同样的事情。
答案1
另一种方法是使用nicematrix
:
\documentclass{article}
\usepackage{booktabs}
\usepackage{nicematrix}
\begin{document}
\begin{table}
\centering
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\begin{NiceTabular}{c m{8em} c m{8em}}
\toprule
\Block{1-3}{\bfseries Heading 1} &&& \Block{1-1}{\bfseries Heading 2}
\\
\cmidrule(r){1-3}
\cmidrule(l){4-4}
l & or, em, ip, su, md, ol, or, si, ta, m, e
& \Block{2-1}{t}
& \Block{2-1}{\parbox{8em}{con, sec, tet, ur, ad, ip, is, ci, ng, e, i, t}}
\\
\cmidrule{1-2}
n & un, ca, ts, em, se, do, rc, ib, la, nd, it
& % t
& % <Heading 2>
\\
\bottomrule
\end{NiceTabular}
\label{tab:table1}
\end{table}
\end{document}
答案2
在 中\multirow
,您应该考虑行数(此处为 4),而不是行数,因为它是为单行单元格设计的。因此,我提出此建议,并附上纠正论点,因为 booktabs 规则在其规则上方和下方添加了一些垂直填充。我还加载了包caption
,以便在标题和表格之间留出合适的间距。
为了将 \multirow 置于最后一列的中心,我没有使用 4 和校正参数,而是使用了另一种可能性:非整数行数(3.3)。
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{caption}
\begin{document}
\begin{table}
\centering
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\begin{tabular}{c c c c}
\toprule
\multicolumn{3}{c}{\bfseries Heading 1}
& \bfseries Heading 2
\\
\cmidrule(r){1-3}
\cmidrule(l){4-4}
l & \multicolumn{1}{m{8em}}{or, em, ip, su, md, ol, or, si, ta, m, e }
& \multirow{4}{*}[1ex]{t}
& \multicolumn{1}{m{8em}}{%
\multirow{3.3}{=}{con, sec, tet, ur, ad, ip, is, ci, ng, e, i, t }}
\\
\cmidrule{1-2}
n & \multicolumn{1}{m{8em}}{un, ca, ts, em, se, do, rc, ib, la, nd, it }
& % t
& % <Heading 2>
\\
\bottomrule
\end{tabular}
\label{tab:table1}
\end{table}
\end{document}
答案3
这是最新版本(≥ 6.0)的解决方案nicematrix
。
\documentclass{article}
\usepackage{booktabs,nicematrix}
\begin{document}
\begin{table}
\centering
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\begin{NiceTabular}{c m{8em} c m[c]{8em}}
\toprule
\RowStyle{\bfseries}
\Block{1-3}{Heading 1} &&& Heading 2
\\
\cmidrule(r){1-3}
\cmidrule(l){4-4}
l & or, em, ip, su, md, ol, or, si, ta, m, e
& \Block{2-1}{t}
& \Block[l]{2-1}{con, sec, tet, ur, ad, ip, is, ci, ng, e, i, t}
\\
\cmidrule{1-2}
n & un, ca, ts, em, se, do, rc, ib, la, nd, it
& % t
& % <Heading 2>
\\
\bottomrule
\end{NiceTabular}
\label{tab:table1}
\end{table}
\end{document}