表格标题居中

表格标题居中

我制作了下表。我对此有两个问题:

  1. 黄色文本充当该面板的“标题”/“说明”。我想将其相对于整个表格居中。但是使用c而不是l并不能使其居中,我相信问题在于我将其设置为multitable。有没有更好的方法来编写这个“标题”以允许我将其居中?
  2. 是否可以缩短表格标题下方的规则,例如删除红色圈出的部分?

在此处输入图片描述

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[labelfont=bf]{caption}

\usepackage{tabularx, multirow, booktabs}
\usepackage{siunitx}

\usepackage{longtable}
\usepackage{dcolumn}
\newlength\summaryTblPanelSep
\setlength\summaryTblPanelSep{-1ex}

\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}
    
    \begin{document}
   

\begin{table}[h!]
\begin{scriptsize}
\centering
\caption{Caption}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{1.10}
\begin{tabular*}{\linewidth}{l@{\extracolsep{\fill}}*{2}{D{.}{.}{-2}}}
\toprule
&\multicolumn{2}{c}{Title}\\
\cmidrule{2-3}
&\alpha &\beta\\\midrule \\ [-2ex]

\multicolumn{2}{l}{\textbf{This is a very long, long, long, long, long, long, caption for this panel}}\\
\midrule
This is config a  &1.11  &2.22\\
This is config b  &-1.11  &-2.22\\
  
\bottomrule
\end{tabular*} 

\end{scriptsize}
\end{table}    

\end{document}

答案1

考虑到@leandriis 的评论,表格可以格式化如下。在我看来,这个表格设计还不错

在此处输入图片描述

\documentclass{article}
\usepackage[skip=1ex, labelfont=bf]{caption}

\usepackage{booktabs, 
            makecell,   % <--- new
            multirow, tabularx}
\renewcommand\theadfont{\small\bfseries}
\usepackage{siunitx}

\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}
\NewExpandableDocumentCommand\mcl{O{1}m} % <--- new
    {\multicolumn{#1}{l}{#2}}

\begin{document}

    \begin{table}[ht]
\caption{Caption}
    \centering
    \renewcommand{\arraystretch}{1.10}
\begin{tabular}{l*{2}{S[table-format=-1.2,
                        table-column-width=4em]}}
    \toprule
                    &   \mcc[2]{Title}              \\
    \cmidrule{2-3}
                    &   $\alpha$    &   $\beta$     \\
    \midrule               
\mcl[3]{\thead[l]{This is a very long, long, long, long,\\
                             long, long, caption for this panel}}      \\
    \midrule
This is config a    &   1.11        &   2.22        \\
This is config b    &  -1.11        &  -2.22        \\
    \bottomrule
\end{tabular}
    \end{table}
\end{document}

附录: 如果您希望表格宽度等于文本宽度,则使用tabularx可能会很方便:

\documentclass{article}
\usepackage[skip=1ex, labelfont=bf]{caption}

\usepackage{booktabs,
            makecell,   % <--- new
            multirow, tabularx}
\renewcommand\theadfont{\small\bfseries}
\usepackage{siunitx}

\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}
\NewExpandableDocumentCommand\mcl{O{1}m} % <--- new
    {\multicolumn{#1}{l}{#2}}

\begin{document}

    \begin{table}[ht]
\caption{Caption}
    \centering
    \renewcommand{\arraystretch}{1.10}
\begin{tabularx}{\linewidth}{X*{2}{S[table-format=-1.2,
                        table-column-width=4em]}}
    \toprule
                    &   \mcc[2]{Title}              \\
    \cmidrule{2-3}
                    &   $\alpha$    &   $\beta$     \\
    \midrule               
\mcl[3]{\thead[l]{This is a very long, long, long, long,
                  long, long, caption for this panel}}      \\
    \midrule
This is config a    &   1.11        &   2.22        \\
This is config b    &  -1.11        &  -2.22        \\
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}

其生产成果为:

在此处输入图片描述

答案2

看看我的建议。

\usepackage{booktabs}
\begin{table}[]
\caption{}
\label{tab:my-table}
\begin{tabular}{@{}lcc@{}}
\toprule
                                     & \multicolumn{2}{c}{Title}                                       \\ \cmidrule(l){2-3} 
                                     & $\alpha$                        & $\beta$                       \\ \cmidrule(l){2-3} 
\multicolumn{3}{c}{\textbf{This is a very long, long, long, long, long, long, caption for this panel}} \\ \midrule
This is config a                     & 1.11                            & 2.22                          \\
This is config b                     & -1.11                           & -2.22                         \\ \bottomrule
\end{tabular}
\end{table}

在此处输入图片描述

相关内容