如何使多列表格中的文本居中?

如何使多列表格中的文本居中?

在此处输入图片描述我创建了一个多列表格。但是,我无法将文本居中对齐。例如,我希望 W 和 N1 位于红色箭头所在的位置。此外,是否可以将标题 Study、Method 和 Dataset 置于中间,如红色字体所示。

提前感谢您花时间解决这个问题。

\documentclass[journal]{IEEEtran}
\bibliographystyle{IEEEtran}
% *** CITATION PACKAGES ***
\usepackage{cite}
\usepackage{multirow, makecell}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\usepackage{floatrow}
\floatsetup[table]{capposition=top}
\usepackage{booktabs,siunitx,showframe} 
\sisetup{table-format=2.1}

\begin{document}

\begin{table*}
    \caption{Some caption}
    \scriptsize
    \centering
    % 19 COL
    \begin{tabular}{p{0.4cm}p{1.5cm}p{0.1cm}p{0.1cm}
                    p{0.3cm}p{0.3cm}p{0.4cm}p{0.4cm}
                    p{0.4cm}p{0.4cm}p{0.4cm}p{0.4cm}
                    p{0.4cm}p{0.4cm}p{0.4cm}p{0.4cm}
                    p{0.4cm}p{0.4cm}p{0.4cm}}

        \toprule
        %       & \multicolumn{8}{c}{\bfseries Emissions} \\
        %       \cmidrule(lr){2-9}
        \multicolumn{1}{c}{Study}
        &\multicolumn{1}{c}{Method}
        &\multicolumn{1}{c}{\makecell[tc]{Num. of\\ subjects}}
        &\multicolumn{1}{c}{Dataset}
        & \multicolumn{5}{c}{Overall metrics}
        & \multicolumn{5}{c}{Class-wise sensitivity}
        & \multicolumn{5}{c}{Class-wise sensitivity} \\
        \cmidrule(lr){5-9}
        \cmidrule(lr){10-14}
        \cmidrule(lr){15-19}

        &&&
        & {Acc.}
        & {$\kappa$}
        & {MF1}
        & {Sens.}
        & {Spec.}
        %%% Class-wise sensitivity
        & {W}
        & {N1}
        & {N2}
        & {N3}
        & {REM}
        %%% Class-wise selectivity
        & {W}
        & {N1}
        & {N2}
        & {N3}
        & {REM}\\
        \midrule

        \cite{Mendonca2019} & {ARNN +RNN}    & {90}& {test} & 98.00 & 98.00 & 98.00 & 98.00& 98.00  & 98.00 & 98.00 & 98.00 & 98.00& 98.00  &98.00 & 98.00 & 98.00 &{--} & 98.00  \\
        \cite{Mendonca2019} & {ABC}    & {90}& {test} & 98.00 & 98.00 & 98.00 & 98.00& 98.00  & 98.00 & 98.00 & 98.00 & 98.00& 98.00  &98.00 & 98.00 & 98.00 &98.00 & 98.00  \\
        \cite{Mendonca2019} & {ABC}    & {90}& {test} & 98.00 & 98.00 & 98.00 & {--} & {--}   & 98.00 & 98.00 & 98.00 & 98.00& 98.00  &98.00 & 98.00 & 98.00 &98.00 & 98.00  \\
        \bottomrule
    \end{tabular}
\end{table*}

\end{document} 

答案1

由于在手头的表格的任何单元格中似乎都不需要自动换行,因此我建议您对 15 个数据列采用tabular*环境(宽度设置为textwidth)和类型列。S

通过这些调整,您可以选择\footnotesize相对\scriptsize字体大小。您的读者会喜欢更大的字体大小。:-)

请注意,我将使用l前两列和c接下来的两列。

在此处输入图片描述

\documentclass[journal]{IEEEtran}
\usepackage{amsmath,booktabs,siunitx} 
\newcommand{\mytab}[1]{% % handy helper macro
   \smash[b]{\begin{tabular}[t]{c}#1\end{tabular}}}

\begin{document}

\begin{table*}
    \sisetup{table-format=2.2}
    \caption{Some caption}
    \footnotesize  %\scriptsize
    \setlength{\tabcolsep}{0pt} % make LaTeX figure out intercol. separation
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} ll cc *{15}{S} }
        \toprule
        Study & Method & \mytab{Num. of\\ subjects} & Dataset
        & \multicolumn{5}{c}{Overall metrics}
        & \multicolumn{5}{c}{Class-wise sensitivity}
        & \multicolumn{5}{c}{Class-wise selectivity} \\
        \cmidrule{5-9} \cmidrule{10-14} \cmidrule{15-19}
        &&& 
        %%% Overall metrics
        & {Acc.} & {$\kappa$} & {MF1} & {Sens.} & {Spec.}
        %%% Class-wise sensitivity
        & {W} & {N1} & {N2} & {N3} & {REM}
        %%% Class-wise selectivity
        & {W} & {N1} & {N2} & {N3} & {REM}\\
        \midrule
        \cite{Mendonca2019} & {ARNN+RNN} & {90}& {test} & 98.00 & 98.00 & 98.00 & 98.00& 98.00  & 98.00 & 98.00 & 98.00 & 98.00& 98.00  &98.00 & 98.00 & 98.00 &{--} & 98.00  \\
        \cite{Mendonca2019} & {ABC}      & {90}& {test} & 98.00 & 98.00 & 98.00 & 98.00& 98.00  & 98.00 & 98.00 & 98.00 & 98.00& 98.00  &98.00 & 98.00 & 98.00 &98.00 & 98.00  \\
        \cite{Mendonca2019} & {ABC}      & {90}& {test} & 98.00 & 98.00 & 98.00 & {--} & {--}   & 98.00 & 98.00 & 98.00 & 98.00& 98.00  &98.00 & 98.00 & 98.00 &98.00 & 98.00  \\
        \bottomrule
    \end{tabular*}
\end{table*}

\end{document} 

相关内容