tabularx 中某一列的垂直对齐方式

tabularx 中某一列的垂直对齐方式

我试图让第一列中的“N”出现在中间,而不是顶部。代码如下:

\documentclass{article}
\usepackage{array}
\usepackage{caption}
\captionsetup{labelformat=empty}
\usepackage[euler]{textgreek}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in]{geometry} % set margins to meet your document's needs
\newcolumntype{Y}{>{\centering\arraybackslash}X} 
   % use ragged-right, not fully-justified, look in narrow columns
\begin{document}
\begin{table}[t]
\caption{Table 2: Length and distance between ditropic contexts in the reading material (measured in words)} 
%\centering  % not needed, since table is as wide as text block
\begin{tabularx}{\textwidth}{@{}lYYYYYY@{}}
\toprule
& {\bfseries N} 
&\multicolumn{3}{c}{\bfseries Length} 
&\multicolumn{2}{c}{\bfseries Distance} \\
 \cmidrule(l){3-5} \cmidrule(l){6-7}
&& tokens
& \textmugreek
& \textsigma
& \textmugreek
& \textsigma\\
\midrule
entire text & --- & 1855 & 14.4 & 6.5 & --- & --- \\
all contexts & 17 & 225 & 13.2 & 5.2 & 91.2 & 68.7 \\
idioms & 9 & 33 & 3.7 & 0.8 & --- & ---\\
idiomatic contexts & 8 & 110 & 13.8 & 5.6 & 170.4 & 110\\
literal contexts & 9 & 115 & 12.8 & 4.7 & 194.4 & 173.4 \\
ditropic pairs & 9 & 225 & --- & --- & 882 & 374.6 \\
\bottomrule
\end{tabularx}
\caption{the entire text contained 129 sentences}
\end{table}
\end{document}

谢谢。

同时想出了类似的解决方案(非常感谢您的帮助,将包括改进):

\usepackage{multirow}
\begin{tabularx}{\textwidth}{@{}lYYYYYY@{}}
\toprule
&\multirow{2}{*}[-2pt]{\bfseries N}
&\multicolumn{3}{c}{\bfseries Length} 
&\multicolumn{2}{c}{\bfseries Distance} \\
\cmidrule(l){3-5} \cmidrule(l){6-7}

答案1

只需使用multirow可选参数并添加小幅修正即可。

我还建议采用另一种布局,将小数点上的数据与包对齐siunitx,并且threeparttable

\documentclass{article}
\usepackage{array}
\usepackage{caption}
\captionsetup{labelformat=empty}
\usepackage[euler]{textgreek}
\usepackage{booktabs,tabularx, multirow, siunitx}
\usepackage[flushleft]{ threeparttable} %
\usepackage[margin=1in]{geometry} % set margins to meet your document's needs
\newcolumntype{Y}{>{\centering\arraybackslash}X}
   % use ragged-right, not fully-justified, look in narrow columns

\begin{document}
\begin{table}[t]
\caption{Table 2: Length and distance between ditropic contexts in the reading material (measured in words)}
%\centering % not needed, since table is as wide as text block
\begin{tabularx}{\textwidth}{@{}l*{6}{Y}@{}}
\toprule
& \multirow{2}{=}[-\dimexpr\aboverulesep+\belowrulesep]{\centering\bfseries N}
&\multicolumn{3}{c}{\bfseries Length}
&\multicolumn{2}{c}{\bfseries Distance} \\
 \cmidrule(l){3-5} \cmidrule(l){6-7}
&& tokens
& \textmugreek
& \textsigma
& \textmugreek
& \textsigma\\
\midrule
entire text & --- & 1855 & 14.4 & 6.5 & --- & --- \\
all contexts & 17 & 225 & 13.2 & 5.2 & 91.2 & 68.7 \\
idioms & 9 & 33 & 3.7 & 0.8 & --- & ---\\
idiomatic contexts & 8 & 110 & 13.8 & 5.6 & 170.4 & 110\\
literal contexts & 9 & 115 & 12.8 & 4.7 & 194.4 & 173.4 \\
ditropic pairs & 9 & 225 & --- & --- & 882 & 374.6 \\
\bottomrule
\addlinespace
\end{tabularx}
\caption{the entire text contained 129 sentences}
\end{table}

\begin{table}[!ht]
\centering
\begin{threeparttable}
\caption{Table 2: Length and distance between ditropic contexts in the reading material (measured in words)}
%\centering % not needed, since table is as wide as text block
\begin{tabular}{@{\,}lcS[table-format=4.0]S[table-format=2.1]c *{2}{S[table-format=3.1]}@{\,}}
\toprule
& \multirow{2}{*}[-\dimexpr\aboverulesep+\belowrulesep]{\bfseries N}
&\multicolumn{3}{c}{\bfseries Length}
&\multicolumn{2}{c}{\bfseries Distance} \\
 \cmidrule(l){3-5} \cmidrule(l){6-7}
&& {tokens}
& {\textmugreek}
& \textsigma
& {\textmugreek}
& {\textsigma}\\
\midrule
entire text & --- & 1855 & 14.4 & 6.5 & {---} &{ ---} \\
all contexts & 17 & 225 & 13.2 & 5.2 & 91.2 & 68.7 \\
idioms & 9 & 33 & 3.7 & 0.8 & {---} & {---}\\
idiomatic contexts & 8 & 110 & 13.8 & 5.6 & 170.4 & 110\\
literal contexts & 9 & 115 & 12.8 & 4.7 & 194.4 & 173.4 \\
ditropic pairs & 9 & 225 &{ ---} & {---} & 882 & 374.6 \\
\bottomrule
\end{tabular}
\smallskip
\begin{tablenotes}
\item{the entire text contained 129 sentences}
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document} 

enter image description here

答案2

您可以使用multirow包裹:

\documentclass{article}
\usepackage{array}
\usepackage{caption}
\captionsetup{labelformat=empty}
\usepackage[euler]{textgreek}
\usepackage{booktabs,tabularx}
\usepackage{multirow}
\usepackage[margin=1in]{geometry} % set margins to meet your document's needs
\newcolumntype{Y}{>{\centering\arraybackslash}X} 
   % use ragged-right, not fully-justified, look in narrow columns
\begin{document}
\begin{table}[t]
\caption{Table 2: Length and distance between ditropic contexts in the reading material (measured in words)} 
%\centering  % not needed, since table is as wide as text block
\begin{tabularx}{\textwidth}{@{}lYYYYYY@{}}
\toprule
& \multirow{2.5}{*}{\bfseries N} 
&\multicolumn{3}{c}{\bfseries Length} 
&\multicolumn{2}{c}{\bfseries Distance} \\
 \cmidrule(l){3-5} \cmidrule(l){6-7}
&& tokens
& \textmugreek
& \textsigma
& \textmugreek
& \textsigma\\
\midrule
entire text & --- & 1855 & 14.4 & 6.5 & --- & --- \\
all contexts & 17 & 225 & 13.2 & 5.2 & 91.2 & 68.7 \\
idioms & 9 & 33 & 3.7 & 0.8 & --- & ---\\
idiomatic contexts & 8 & 110 & 13.8 & 5.6 & 170.4 & 110\\
literal contexts & 9 & 115 & 12.8 & 4.7 & 194.4 & 173.4 \\
ditropic pairs & 9 & 225 & --- & --- & 882 & 374.6 \\
\bottomrule
\end{tabularx}
\caption{the entire text contained 129 sentences}
\end{table}
\end{document}

N centred in 2 and a half rows

我用了 2.5 行行数的参数\multirow,因为booktabs'\midrule增加了一些额外的空间。因此,多行应该高于没有规则的两行。

相关内容