请考虑以下示例:
\documentclass{article}
\usepackage{siunitx}
\DeclareSIUnit[mode = text]\kroner{kr.}
\usepackage{booktabs,multirow}
\newcommand*\mr[2]{\multirow{#1}{*}{#2}}
\newcommand*\mc[2]{\multicolumn{#1}{c}{#2}}
\newcommand*\specialcell[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\begin{document}
\begin{tabular}{
l
S[table-format = 3]
S[table-format = 2.2]
}
\toprule
\mr{2}{\specialcell{Dansk\\ honning}}
& \mc{2}{$1$~b{\ae}ger} \\
\cmidrule{2-3}
& \mc{1}{Masse~(\si{\g})}
& \mc{1}{Pris~(\si{\kroner})} \\
\midrule
Almindelig
& 450 & 14.95 \\
\bottomrule
\end{tabular}
\end{document}
我如何Dansk honning
相对于前两行垂直居中?
我得出的结论是,问题发生的原因是在周围添加了一些空间\cmidrule
。
答案1
您可以将多行内容的位置调整大约 -(\aboverulesep + \belowrulesep)/2。-0.4ex
似乎没问题。此外,我将您的\multirow{2}{*}{\specialcell{…}}
命令替换\multirowcell
为makecell
,它的作用相同,并且可以进一步定制(字体、水平和垂直对齐等):
\documentclass{article}
\usepackage{siunitx}
\DeclareSIUnit[mode = text]\kroner{kr.}
\usepackage{booktabs,multirow}
\newcommand*\mc[2]{\multicolumn{#1}{c}{#2}}
\usepackage{makecell}
\begin{document}
\begin{tabular}{
l
S[table-format = 3]
S[table-format = 2.2]
}
\toprule
\multirowcell{2}[-0.4ex]{Dansk\\honning}
& \mc{2}{$1$~b{\ae}ger} \\
\cmidrule{2-3}
& \mc{1}{Masse~(\si{\g})}
& \mc{1}{Pris~(\si{\kroner})} \\
\midrule
Almindelig
& 450 & 14.95 \\
\bottomrule
\end{tabular}
\end{document}