如何控制表格列文本的垂直对齐方式

如何控制表格列文本的垂直对齐方式

我有一张类似下面的表格。我想将第一列的文本移动到垂直对齐到中心。该怎么做?

在此处输入图片描述

剧本:

%README: this copy with comprehensive attack and defences description.

\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}
\ifCLASSOPTIONcompsoc
  % IEEE Computer Society needs nocompress option
  % requires cite.sty v4.0 or later (November 2003)
  \usepackage[nocompress]{cite}
\else
  % normal IEEE

  \usepackage{cite}
\fi
\ifCLASSINFOpdf
\else
\fi

\usepackage{colortbl}       
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\newcommand*\rot{\rotatebox{90}}
\usepackage{tabularx}

\usepackage{msc}
\usepackage{xcolor}
\newcommand{\quotes}[1]{``#1''} %for qoutation marks

\DeclareRobustCommand*{\IEEEauthorrefmark}[1]{%
\raisebox{0pt}[0pt][0pt]{\textsuperscript{\footnotesize\ensuremath{#1}}}}

\begin{document}
\title{Test}

\section{Section Contains Footnote}
\maketitle

\begin{table}[bt!] 
\caption{Title}
\resizebox{\columnwidth}{!} {
\begin{tabular} {lccccc}
\hline
\multicolumn{1}{c}{A} 
&&\multicolumn{3}{c}{B} \\   
\cmidrule(lr){3-5} 
\\
& &  AAA & BBB & CCC 
\\ \hline
\rowcolor[gray]{.9} 
Text1 & & \cmark & \cmark & \cmark \\
Text2 & & \xmark & \cmark & \xmark \\
\rowcolor[gray]{.9} 
Text3  & & \cmark & \xmark & \xmark \\
Text4  & & \cmark & \cmark & \cmark \\
\hline
\end{tabular}
}%end resize box
\end{table}

\end{document}

答案1

由于你在其他包中也加载了multirow,因此你可以在你的情况下利用它:

\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}

\usepackage{pifont}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\usepackage{booktabs, multirow}

\begin{document}
\begin{tabular}{ l *{45}{c} }
  \toprule
    &   \multicolumn{3}{c}{B} \\
  \cmidrule(lr){2-4}
  \multicolumn{1}{c}{\multirow{-2}{*}[0.5ex]{A}}
    &   AAA & BBB & CCC \\
  \midrule
  Text1 &   \cmark & \cmark & \cmark \\
  Text2 &   \xmark & \cmark & \xmark \\
  Text3 &   \cmark & \xmark & \xmark \\
  Text4 &   \cmark & \cmark & \cmark \\
  \bottomrule
\end{tabular}

\end{document}

在此处输入图片描述

答案2

您可以从第二行将列标题提升到位,并完全消除这可能导致的任何高度/深度变化:

在此处输入图片描述

\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}

\usepackage{booktabs,pifont}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%

\begin{document}

\begin{tabular}{ l *{5}{c} }
  \toprule
  & & \multicolumn{3}{c}{B} \\
  \cmidrule(lr){3-5}
  \multicolumn{1}{c}{\raisebox{.65\normalbaselineskip}[0pt][0pt]{A}}
    & & AAA & BBB & CCC \\
  \midrule
  Text1 & & \cmark & \cmark & \cmark \\
  Text2 & & \xmark & \cmark & \xmark \\
  Text3 & & \cmark & \xmark & \xmark \\
  Text4 & & \cmark & \cmark & \cmark \\
  \bottomrule
\end{tabular}

\end{document}

注意使用所有的booktabs规则(如\toprule,, ...)而不是传统(如)和规则\bottomrule的混合。\hlinebooktabs

选择.65\normalbaselineskip完全是任意的 - 大于.5\normalbaselineskip,这将使您位于 内常规行的一半tabular。额外的部分.15\normalbaselineskip是由于 的宽度\cmidrule和软件包添加的一些额外空白booktabs来扩展内容。修改它以满足您的需要。

答案3

使用multirow+ 进行小幅调整(由于 booktabs 规则的填充)解决了该问题。由于您交替使用行颜色,我color使用xcolor+table选项替换,以使用\rowcolor{oddrowcolor}{evenrowcolor} scheme.resizebox isn't required here, and anyway it shouldn't be used with tables, as it gives inconsistent fonts sizing. Better play with the font size and/ortabcolsep`。

\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}
\ifCLASSOPTIONcompsoc
  % IEEE Computer Society needs nocompress option
  % requires cite.sty v4.0 or later (November 2003)
  \usepackage[nocompress]{cite}
\else
  % normal IEEE

  \usepackage{cite}
\fi
\ifCLASSINFOpdf
\else
\fi

\usepackage[table, svgnames]{xcolor}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\newcommand*\rot{\rotatebox{90}}
\usepackage{multirow, tabularx}
\usepackage{lipsum}
\usepackage{msc}
\usepackage{xcolor}
\newcommand{\quotes}[1]{``#1''} %for quotation marks

\DeclareRobustCommand*{\IEEEauthorrefmark}[1]{%
\raisebox{0pt}[0pt][0pt]{\textsuperscript{\footnotesize\ensuremath{#1}}}}

\begin{document}

\title{Test}

\section{Section Contains Footnote}
\maketitle

\begin{table}[bt!]
\centering
\caption{Title}
\rowcolors{4}{}{Gainsboro}
\begin{tabular} {lccccc}
\toprule
\multirow{2}{*}[-0.6ex]{A}&&\multicolumn{3}{c}{B} \\
\cmidrule(lr){3-5}
& & AAA & BBB & CCC
\\ \hline
Text1 & & \cmark & \cmark & \cmark \\
Text2 & & \xmark & \cmark & \xmark \\
Text3 & & \cmark & \xmark & \xmark \\
Text4 & & \cmark & \cmark & \cmark \\
\bottomrule
\end{tabular}
\end{table}
\lipsum[1-6]

\end{document} 

在此处输入图片描述

相关内容