表格中多列文本居中并进行列合并

表格中多列文本居中并进行列合并

我想对齐 Euclidean_L1 文本中心。我正在从 Excel2Latex 插件生成表格,尽管“Euclidean_L1”

代码

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{cccccr}
    \toprule
    \multirow{2}[4]{*}{Models} & \multicolumn{5}{p{15.215em}}{Euclidean\_L1} \\
\cmidrule{2-6}          & Prec  & Recall & F1-Sco & Acc   & \multicolumn{1}{c}{AUC} \\
    \midrule
    OpenFace & 52.41 & 53.69 & 53.04 & 52.67 & \multicolumn{1}{c}{55} \\
    DeepID & 52.75 & 38.97 & 44.83 & 52.24 & \multicolumn{1}{c}{52.51} \\
    DeepFace & 53    & 45.08 & 48.72 & 52.76 & \multicolumn{1}{c}{54.03} \\
    FaceNet & 56.75 & 57.94 & 57.34 & 57.08 & \multicolumn{1}{c}{62.25} \\
    \midrule
    VGGFace & \textcolor[rgb]{ 1,  0,  0}{\textbf{64.27}} & \textcolor[rgb]{ 1,  0,  0}{\textbf{48.98}} & \textcolor[rgb]{ 1,  0,  0}{\textbf{55.59}} & \textcolor[rgb]{ 1,  0,  0}{\textbf{61.04}} &  \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%

截屏

在此处输入图片描述

答案1

为了使 的内容水平居中\multicolumn,请使用c而不是p{15.215em}

我还通过使用预定义的颜色简化了您的代码red,并且删除了所有不必要的\multicolumn{1}{c}命令。

为了进行比较,我还提供了第二个示例,用于siunitx改进表格中数字的对齐方式。(另外,你真的需要红色吗? 粗体文本突出显示最后一列的数字?其中一个不是已经足够了吗?

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{xcolor}


%%% only used in the second example code:
\usepackage{siunitx}
\usepackage{etoolbox}
\newrobustcmd{\Red}{\color{red}}
\robustify\bfseries

\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{cccccc}
    \toprule
    \multirow{2}[4]{*}{Models} & \multicolumn{5}{c}{Euclidean\_L1} \\
\cmidrule{2-6}          & Prec  & Recall & F1-Sco & Acc   & {AUC} \\
    \midrule
    OpenFace & 52.41 & 53.69 & 53.04 & 52.67 & 55 \\
    DeepID & 52.75 & 38.97 & 44.83 & 52.24 & 52.51 \\
    DeepFace & 53    & 45.08 & 48.72 & 52.76 & 54.03 \\
    FaceNet & 56.75 & 57.94 & 57.34 & 57.08 & 62.25 \\
    \midrule
    VGGFace & \textcolor{red}{\textbf{64.27}} & \textcolor{red}{\textbf{48.98}} & \textcolor{red}{\textbf{55.59}} & \textcolor[rgb]{ 1,  0,  0}{\textbf{61.04}} &  \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{l*{5}{S[table-format=2.2, detect-weight]}}
    \toprule
    Models & \multicolumn{5}{c}{Euclidean\_L1} \\
\cmidrule{2-6}          & {Prec}  & {Recall} & {F1-Sco} & {Acc}   & {AUC} \\
    \midrule
    OpenFace & 52.41 & 53.69 & 53.04 & 52.67 & 55 \\
    DeepID & 52.75 & 38.97 & 44.83 & 52.24 & 52.51 \\
    DeepFace & 53    & 45.08 & 48.72 & 52.76 & 54.03 \\
    FaceNet & 56.75 & 57.94 & 57.34 & 57.08 & 62.25 \\
    \midrule
    VGGFace & \Red 64.27 & \bfseries 48.98 & \Red\bfseries 55.59 & 61.04 &  \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%


\end{document}

相关内容