我使用multirow
环境将文本横跨两行。由于它不支持\\
插入换行符,因此我将其嵌套到shortstack
(请参阅下面的 MWE)。但是,在这两种情况下(单行文本、双行文本),文本都没有真正居中。我做错了什么?
示例图像
红线表示标题行的中心(跨越两行)。如图所示,这两条线实际上都不是垂直居中的。
平均能量损失
\documentclass[a4paper,twocolumn]{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage[a4paper,top=3cm,bottom=2cm,left=1.5cm,right=1.5cm,marginparwidth=1.75cm]{geometry}
\title{Your Paper}
\author{You}
\begin{document}
\begin{table}[htbp]
\caption{Classifier configurations and their performance.}
\label{tblClassifierConfig}
\begin{tabular*}{1.2\columnwidth}{@{\extracolsep{\fill}}lrllll@{}}
\toprule
\multirow{2}{*}{\raisebox{-\heavyrulewidth}{\shortstack[l]{\textbf{N-gram}\\as Range}}} & \multirow{2}{*}{\raisebox{-\heavyrulewidth}{\shortstack[l]{\textbf{Vocab. Size}\\in \#n-grams}}} & \multicolumn{2}{c}{Test Set 1} & \multicolumn{2}{c}{Test Set 2} \\
\cmidrule(l){3-6} & & \textbf{Prec.} & \textbf{Recall} & \textbf{Prec.} & \textbf{Recall} \\ \midrule
(2,4)-char & 500 & 0.9999 & 0.9999 & 0.5085 & 0.5849 \\
(2,4)-char & 1000 & 0.9999 & 0.9999 & 0.5114 & 0.6132 \\
(2,3)-word & 1,500 & 0.9999 & 0.9999 & 0.5134 & 0.6268 \\
(1,3)-word & 2,000 & 0.9999 & 0.9999 & 0.5138 & 0.6307 \\ \bottomrule
\end{tabular*}
\end{table}
\end{document}
答案1
在multirow
单元格中,您还需要考虑引入的垂直空间\cmidrule
。它与行高有关0.4
,因此您可以写
\multirow{2.4}{*}{ ...}
我还建议在带有数字的列中使用包S
中的列类型siunitx
,而不是增加表格宽度(它将在下一列中突出)。相反,这样做会减少tabocolsep
:
\documentclass[a4paper,twocolumn,english]{article}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage{booktabs, makecell, multirow}
\usepackage{siunitx}
\usepackage[a4paper,
top=3cm,bottom=2cm,left=1.5cm,right=1.5cm,
marginparwidth=1.75cm]{geometry}
\usepackage{lipsum}
\title{Your Paper}
\author{You}
\begin{document}
\lipsum[11]
\begin{table}[htbp]
\caption{Classifier configurations and their performance.}
\label{tblClassifierConfig}
\setlength\tabcolsep{0pt}
\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}}
l
S[table-format=4.0,
group-four-digits,
group-separator=\,]
*{4}{S[table-format=1.4]}
}
\toprule
\multirow{2.4}{*}{\makecell{\textbf{N-gram}\\as Range}}
& {\multirow{2.4}{*}{\makecell{\textbf{Vocab. Size}\\in \#n-grams}}}
& \multicolumn{2}{c}{Test Set 1}
& \multicolumn{2}{c}{Test Set 2} \\
\cmidrule{3-4}
\cmidrule{5-6}
& & {\textbf{Prec.}} & {\textbf{Recall}} & {\textbf{Prec.}} & {\textbf{Recall}} \\
\midrule
(2,4)-char & 500 & 0.9999 & 0.9999 & 0.5085 & 0.5849 \\
(2,4)-char & 1 000 & 0.9999 & 0.9999 & 0.5114 & 0.6132 \\
(2,3)-word & 1 500 & 0.9999 & 0.9999 & 0.5134 & 0.6268 \\
(1,3)-word & 2 000 & 0.9999 & 0.9999 & 0.5138 & 0.6307 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
这使
答案2
带有 的变体\multirowcell
。该 makecell
包允许在标准单元格中使用换行符,以及通用格式(此处未使用)。请注意,您的表格大于列宽,因此它将溢出到右侧的列中。我加载了caption
标题和表格之间的合理垂直间距。另外,我想知道\marginparwidth
当水平边距设置为 1.5 厘米时 1.75 厘米意味着什么。
\documentclass[a4paper,twocolumn]{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multirow}
\usepackage{booktabs, makecell, caption}
\captionsetup{skip=6pt}
\usepackage[a4paper,top=3cm, bottom=2cm, hmargin=1.5cm,marginparwidth=1.75cm, showframe]{geometry}
\usepackage{lipsum}
\title{Your Paper}
\author{You}
\begin{document}
\lipsum[11]
\begin{table}[!htbp]
\caption{Classifier configurations and their performance.}
\label{tblClassifierConfig}
\begin{tabular*}{1.2\columnwidth}{@{\extracolsep{\fill}}lrllll@{}}
\toprule
\multirowcell{2.3}{\textbf{N-gram}\\as Range} & \multirowcell{2.3}{\textbf{Vocab. Size}\\in \#n-grams} & \multicolumn{2}{c}{Test Set 1} & \multicolumn{2}{c}{Test Set 2} \\
\cmidrule(l){3-6} & & \textbf{Prec.} & \textbf{Recall} & \textbf{Prec.} & \textbf{Recall} \\ \midrule
(2,4)-char & 500 & 0.9999 & 0.9999 & 0.5085 & 0.5849 \\
(2,4)-char & 1000 & 0.9999 & 0.9999 & 0.5114 & 0.6132 \\
(2,3)-word & 1,500 & 0.9999 & 0.9999 & 0.5134 & 0.6268 \\
(1,3)-word & 2,000 & 0.9999 & 0.9999 & 0.5138 & 0.6307 \\ \bottomrule
\end{tabular*}
\end{table}
\end{document}
答案3
使用stackengine
,我将其更改\shortstack
为长\stackanchor
,但(重要的是)还在堆栈上方和下方添加了一个 4pt 垂直缓冲区。
\documentclass[a4paper,twocolumn]{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage[usestackEOL]{stackengine}
\usepackage[a4paper,top=3cm,bottom=2cm,left=1.5cm,right=1.5cm,marginparwidth=1.75cm]{geometry}
\def\stacktype{L}
\setstackgap{S}{4pt}
\title{Your Paper}
\author{You}
\begin{document}
\begin{table}[htbp]
\caption{Classifier configurations and their performance.}
\label{tblClassifierConfig}
\begin{tabular*}{1.2\columnwidth}{@{\extracolsep{\fill}}lrllll@{}}
\toprule
\multirow{2}{*}{\raisebox{-\heavyrulewidth}{\addstackgap{\stackanchor{\textbf{N-gram}}{as Range}}}} & \multirow{2}{*}{\raisebox{-\heavyrulewidth}{\addstackgap{\stackanchor{\textbf{Vocab. Size}}{in \#n-grams}}}} & \multicolumn{2}{c}{Test Set 1} & \multicolumn{2}{c}{Test Set 2} \\
\cmidrule(l){3-6} & & \textbf{Prec.} & \textbf{Recall} & \textbf{Prec.} & \textbf{Recall} \\ \midrule
(2,4)-char & 500 & 0.9999 & 0.9999 & 0.5085 & 0.5849 \\
(2,4)-char & 1000 & 0.9999 & 0.9999 & 0.5114 & 0.6132 \\
(2,3)-word & 1,500 & 0.9999 & 0.9999 & 0.5134 & 0.6268 \\
(1,3)-word & 2,000 & 0.9999 & 0.9999 & 0.5138 & 0.6307 \\ \bottomrule
\end{tabular*}
\end{table}
\end{document}