在多行表中垂直居中对齐表格数据

在多行表中垂直居中对齐表格数据

我的MWE如下:

\documentclass[conference]{IEEEtran}
% correct bad hyphenation here
\hyphenation{}


\usepackage{array}
\usepackage{tabularx}
\usepackage{subcaption,siunitx,booktabs}
\usepackage[margin=1in]{geometry}
\usepackage{multirow, makecell}
\usepackage{array}
\setlength\extrarowheight{2pt}

\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%

\begin{document}

\begin{table*}
    \begin{subtable}{1\textwidth}
        \centering
        \begin{tabular}{|c|c|c|c|c|c|c|c|p{4cm}|}%{cclcccccc}
            \hline
            \multirow{2}{*}{\shortstack[c]{\textbf{Column}\\ \textbf{one}}} &
            \multirow{2}{*}{\shortstack[c]{\textbf{Column}\\ \textbf{two}}} &
            \multirow{2}{*}{\textbf{Column 3}} &
            \multirow{2}{*}{\textbf{Column 4}} &
            \multirow{2}{*}{\textbf{Column 5}} &
            \multicolumn{3}{c|}{\textbf{Column 6}} & \multirow{2}{*}{\textbf{Column 7}} \\ \cline{6-8}
            & & & & & {\textbf{A}} & {\textbf{B}} & {\textbf{C}}
            & \\
            \hline
             \multirow{3}{*}{aaaaa} & \multirow{3}{*}{\shortstack[l]{Type\\ one}} 
                        & A1       & \cmark & \xmark & CRM1 & FF1 & SFR1 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. \\ \cline{3-9}
                    &   & A2& \cmark & \cmark & CRM2 & FiF2 & SiFR2 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. \\ \cline{3-9}
                    &   & A3          & \cmark & \xmark & CRM3 & FiF3 & SiFR3 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. \\ \cline{3-9}
           \hline
        \end{tabular}
        \caption{First subtable1}\label{tab:sub_first1}
    \end{subtable}
    \caption{Three simple tables} \label{tab:three_tables}
\end{table*}

\end{document}

结果表格如下:

在此处输入图片描述

因为我想让第 7 列更宽,所以我使用了p{<width>}参数。但是,其余单元格中的所有文本现在都垂直对齐。

所以,

  1. 是否可以将它们垂直居中对齐?

  2. 列标题“第 7 列”应水平居中对齐。有没有办法只应用于该单元格?

答案1

  1. 使用m{...}而不是p{}将使单元格居中对齐

  2. 将最后一列标题居中对齐:\multicolumn{1}{c|}{\multirow{2}{*}{\textbf{Column 7}}}


\documentclass[conference]{IEEEtran}
% correct bad hyphenation here
\hyphenation{}



\usepackage{array}
\usepackage{tabularx}
\usepackage{subcaption,siunitx,booktabs}
\usepackage[margin=1in]{geometry}
\usepackage{multirow, makecell}
\usepackage{array}
\setlength\extrarowheight{2pt}

\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%

\begin{document}

\begin{table*}
    \begin{subtable}{1\textwidth}
        \centering
        \begin{tabular}{|c|c|c|c|c|c|c|c|m{4cm}|}%{cclcccccc}
            \hline
            \multirow[b]{2}{*}{\shortstack[t]{\textbf{Column}\\ \textbf{one}}} &
            \multirow[b]{2}{*}{\shortstack[t]{\textbf{Column}\\ \textbf{two}}} &
            \multirow{2}{*}{\textbf{Column 3}} &
            \multirow{2}{*}{\textbf{Column 4}} &
            \multirow{2}{*}{\textbf{Column 5}} &
            \multicolumn{3}{c|}{\textbf{Column 6}} & \multicolumn{1}{c|}{\multirow{2}{*}{\textbf{Column 7}}} \\ \cline{6-8}
            & & & & & {\textbf{A}} & {\textbf{B}} & {\textbf{C}}
            & \\
            \hline
             \multirow{10}{*}{aaaaa} & \multirow{10}{*}{\shortstack[lb]{Type\\ one}} 
                        & A1       & \cmark & \xmark & CRM1 & FF1 & SFR1 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. \\ \cline{3-9}
                    &   & A2& \cmark & \cmark & CRM2 & FiF2 & SiFR2 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. \\ \cline{3-9}
                    &   & A3          & \cmark & \xmark & CRM3 & FiF3 & SiFR3 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. \\ \cline{3-9}
           \hline
        \end{tabular}
        \caption{First subtable1}\label{tab:sub_first1}
    \end{subtable}
    \caption{Three simple tables} \label{tab:three_tables}
\end{table*}

\end{document}

在此处输入图片描述

答案2

只需使用m而不是p

\documentclass[conference]{IEEEtran}
% correct bad hyphenation here
\hyphenation{}

\usepackage{array}
\usepackage{tabularx}
\usepackage{subcaption,siunitx,booktabs}
\usepackage[margin=1in]{geometry}
\usepackage{multirow, makecell}
\usepackage{array}
    \setlength\extrarowheight{2pt}

\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
    \newcommand{\cmark}{\ding{51}}%
    \newcommand{\xmark}{\ding{55}}%

\begin{document}
\begin{table*}
    \begin{subtable}{1\textwidth}
        \centering
        \begin{tabular}{|c|c|c|c|c|c|c|c|m{4cm}|}%{cclcccccc}
            \hline
            \multirow{2}{*}{\shortstack[c]{\textbf{Column}\\ \textbf{one}}} &
            \multirow{2}{*}{\shortstack[c]{\textbf{Column}\\ \textbf{two}}} &
            \multirow{2}{*}{\textbf{Column 3}} &
            \multirow{2}{*}{\textbf{Column 4}} &
            \multirow{2}{*}{\textbf{Column 5}} &
            \multicolumn{3}{c|}{\textbf{Column 6}} & \multirow{2}{*}{\textbf{Column 7}} \\ \cline{6-8}
            & & & & & {\textbf{A}} & {\textbf{B}} & {\textbf{C}}
            & \\
            \hline
             \multirow{3}{*}{aaaaa} & \multirow{3}{*}{\shortstack[l]{Type\\ one}} 
                        & A1       & \cmark & \xmark & CRM1 & FF1 & SFR1 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. \\ \cline{3-9}
                    &   & A2& \cmark & \cmark & CRM2 & FiF2 & SiFR2 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. \\ \cline{3-9}
                    &   & A3          & \cmark & \xmark & CRM3 & FiF3 & SiFR3 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. \\ \cline{3-9}
           \hline
        \end{tabular}
        \caption{First subtable1}\label{tab:sub_first1}
    \end{subtable}
    \caption{Three simple tables} \label{tab:three_tables}
\end{table*}
\end{document}

在此处输入图片描述

相关内容