多行表格垂直居中

多行表格垂直居中

我有一张包含多行列的表格,我可以对其使用 booktabs 和 multirow 包。

\documentclass[12pt, twocolumn]{article}

\usepackage{booktabs}
\usepackage{multirow}

\newcommand{\blah}{blah blah blah blah blah blah blah blah blah blah blah blah blah blah}
\newcommand{\blahx}{blah blah blah blah blah blah blah}

\begin{document}

\begin{table}[ht]
\caption{Stories}\label{tab:scenarios}
\centering
\def\arraystretch{1.2}%  1 is the default, change whatever you need
\begin{tabular}{c|p{4.4cm}|p{2.2cm}}\toprule
{\bf Story} & {\bf Description} & {\bf Properties} \\
\midrule\hline

% item 1/2 
\multirow{2}{*}{s1} & \blah
    & \multirow{4}{2.4cm}{\blahx}\\
\cline{1-2}
\multirow{2}{*}{s2} & \blah
 & \\

\hline

% item 3/4 
\multirow{2}{*}{s3} & \blah
  & \multirow{4}{2.4cm}{\blahx} \\
\cline{1-2}
\multirow{2}{*}{s4} & \blah
 & \\

\hline

% item 5/6 
\multirow{2}{*}{s5} & \blah
 & \multirow{4}{2.4cm}{\blahx}\\
\cline{1-2}
\multirow{2}{*}{s6} & \blah
 & \\

% Closing table
\hline\bottomrule
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

当表格内容字符串较小时,表格看起来还不错。但是,使用多行的第一列(可能是第二列)和最后一列不是垂直居中。如何使其垂直居中?

答案1

将列限定符替换pm。第一列不需要任何多行。最后,我建议删除所有垂直规则,以及更少的水平规则,并将其替换为\addlinespaces:

\documentclass[12pt, twocolumn]{article}

\usepackage{booktabs}
\usepackage{array, multirow, caption}

\begin{document}

\begin{table}[ht]
  \caption{Stories}\label{tab:scenarios}
  \centering
  \def\arraystretch{1.2}% 1 is the default, change whatever you need
  \begin{tabular}{@{}cm{4.4cm}m{2.2cm}@{}}
    \toprule
    {\bfseries Story} & {\bfseries Description} & {\bfseries Properties} \\
    \midrule\midrule
    % item 1/2
    {s1} & PAID Sample project assignment (err on the side of paying fairly for estimated completion time
    & \multirow{4}{2.4cm}{Sample project assignment (err on the side of paying fairly}\\
    \addlinespace
    s2 & PAID Sample project assignment (err on the side of paying fairly for estimated completion time
    & \\
    \midrule
    % item 3/4
    s3 & PAID Sample project assignment (err on the side of paying fairly for estimated completion time
    & \multirow{4}{2.4cm}{Sample project assignment (err on the side of paying fairly} \\
    \addlinespace
    s4 & PAID Sample project assignment (err on the side of paying fairly for estimated completion time
    & \\
    \midrule
    % item 5/6
    s5 & PAID Sample project assignment (err on the side of paying fairly for estimated completion time
    & \multirow{4}{2.4cm}{Sample project assignment (err on the side of paying fairly}\\
    %\cmidrule{1-2}
    \addlinespace
    s6 & PAID Sample project assignment (err on the side of paying fairly for estimated completion time
    & \\
    % Closing table
    \midrule\bottomrule
  \end{tabular}
\end{table}

\end{document} 

在此处输入图片描述

相关内容