自定义表头

自定义表头

我有以下代码:

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[margin=2.5cm]{geometry}
\usepackage{multirow}
\usepackage{mathtools}
\usepackage{caption}
\usepackage{booktabs}
\usepackage[labelfont=bf]{caption}
\begin{document}
\def\arraystretch{1.25}
\begin{table}%[h]
\centering
\captionof{table}{\textbf{Descriptive Statistics on Some         
Variables}\\\small{Lorem ipsum dolor sit amet, consectetur adipiscing             
elit, sed do eiusmod tempor incididunt ut labore et dolore magna 
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco 
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor 
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa 
qui officia deserunt mollit anim id est laborum.}}
\resizebox{\columnwidth}{!}{
\begin{tabular}{lrrrrrrr}
\toprule
\multicolumn{1}{c}{Description}&&
\multicolumn{1}{c}{Variable A}&
\multicolumn{1}{c}{Variable B}&
\multicolumn{1}{c}{Variable C}&
\multicolumn{1}{c}{Variable D}&
\multicolumn{1}{c}{Variable E}&
\multicolumn{1}{c}{Variable F}\\\hline
Mean                &&0.43      &0.24   &0.32   &0.34   &0.32   &0.39\\
Median              &&0.89      &0.48   &0.22   &0.36   &0.15   &0.24\\
Standard Deviation  &&4.06      &1.31   &2.27   &1.46   &1.58   &3.57\\
Variance            &&17.22     &3.35   &5.17   &2.13   &3.33   &15.60\\
Kurtosis            &&1.22      &2.45   &5.37   &2.04   &4.93   &7.62\\
Skewness            &&-0.12     &-0.51  &0.57   &-0.06  &0.31   &-0.39\\
Range               &&30.33     &16.79  &21.18  &11.51  &16.50  &42.57\\
Minimum             &&-19.62    &-8.82  &-9.54  &-5.41  &-6.38  &-24.16\\
Maximum             &&11.11     &7.47   &11.64  &6.10   &9.22   &17.51\\
Count               &&326       &316    &321    &226    &426    &454\\
\bottomrule
\end{tabular}
}
\end{table}
\end{document}

输出结果如下:

在此处输入图片描述

我的问题是我想让表格标题居中,但让表格描述保持对齐。我尝试了各种解决方案,例如 \usepackage[labelfont=bf]{caption} 等。但是,当我尝试让标题居中时,表格描述也会居中。理想情况下,我希望能够制作一个表格标题,如下所示:

在此处输入图片描述

提前非常感谢您!

答案1

像这样:

在此处输入图片描述

代码类似伯纳德有差异的回答:

  • 将表格编号更改为\Roman
  • 用来\caption代替captionof
  • 使用tabular*表环境

\documentclass[11pt]{article}
\usepackage[margin=2.5cm, showframe]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[skip=0.33\baselineskip]{caption}
\captionsetup[table]{
    font=bf,
    justification=centerlast,
    labelsep=newline
                    }
\renewcommand\thetable{\Roman{table}}

\usepackage{lipsum}
\begin{document}

\begin{table}%[h]
    \centering
    \setlength\tabcolsep{0pt}
    \sisetup{table-format=2.2}
\caption{Descriptive Statistics on Some
Variables}

\parbox{\linewidth}{\small \lipsum[11]}

\medskip
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
                l
                S[table-format=-2.2]
           *{5}{S}
                }
\toprule
\multicolumn{1}{c}{Description}
            & {Variable A} & {Variable B} & {Variable C}
            & {Variable D} & {Variable E} & {Variable F}        \\
\midrule
Mean        &   0.43 &  0.24 &  0.32 &  0.34 &  0.32 &  0.39    \\
Median      &   0.89 &  0.48 &  0.22 &  0.36 &  0.15 &  0.24    \\
Standard Deviation
            &   4.06 &  1.31 &  2.27 &  1.46 &  1.58 &  3.57    \\
Variance    &  17.22 &  3.35 &  5.17 &  2.13 &  3.33 &  15.60   \\
Kurtosis    &   1.22 &  2.45 &  5.37 &  2.04 &  4.93 &   7.62   \\
Skewness    &  -0.12 & -0.51 &  0.57 & -0.06 &  0.31 &  -0.39   \\
Range       &  30.33 & 16.79 & 21.18 & 11.51 & 16.50 &  42.57   \\
Minimum     & -19.62 & -8.82 & -9.54 & -5.41 & -6.38 & -24.16   \\
Maximum     &  11.11 &  7.47 & 11.64 &  6.10 &  9.22 &  17.51   \\
    \addlinespace
Count       & {326}  & {316} & {321} & {226} & {426} & {454}    \\
    \bottomrule
\end{tabular*}
    \end{table}
\end{document}

答案2

您可以使用centering选项和 a\parbox来描述表格。在这种情况下,您应该使用可选参数,这样描述就不会出现在表格列表中。我还使用S中的列类型改进了整体外观siunitx,使数字在小数点上对齐(最后一行除外):

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[margin=2.5cm, showframe]{geometry}
\usepackage{multirow}
\usepackage{mathtools}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage[labelfont=bf, justification=centering]{caption}

\begin{document}

\begin{table}%[h]
\def\arraystretch{1.25}
\sisetup{table-format=2.2, table-number-alignment=center, table-column-width=18mm}
\setlength{\tabcolsep}{5pt}
\centering
\captionof{table}{\textbf{Descriptive Statistics on Some
Variables}\\[1ex]\parbox{\linewidth}{\small Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa
qui officia deserunt mollit anim id est laborum.}}
\begin{tabular}{@{}lS[table-format=-2.2]*{4}{S}S[table-format=-2.2]@{}}
\toprule
\multicolumn{1}{c}{Description}&{Variable A} & {Variable B} & {Variable C} & {Variable D} & {Variable E} & {Variable F}\\
\midrule
Mean & 0.43 & 0.24 & 0.32 & 0.34 & 0.32 & 0.39 \\
Median & 0.89 & 0.48 & 0.22 & 0.36 & 0.15 & 0.24 \\
Standard Deviation & 4.06 & 1.31 & 2.27 & 1.46 & 1.58 & 3.57 \\
Variance & 17.22 & 3.35 & 5.17 & 2.13 & 3.33 & 15.60 \\
Kurtosis & 1.22 & 2.45 & 5.37 & 2.04 & 4.93 & 7.62 \\
Skewness & -0.12 & -0.51 & 0.57 & -0.06 & 0.31 & -0.39 \\
Range & 30.33 & 16.79 & 21.18 & 11.51 & 16.50 & 42.57 \\
Minimum & -19.62 & -8.82 & -9.54 & -5.41 & -6.38 & -24.16 \\
Maximum & 11.11 & 7.47 & 11.64 & 6.10 & 9.22 & 17.51 \\
\addlinespace
Count & {326} & {316} & {321} & {226} & {426} & {454} \\
\bottomrule
\end{tabular}
\end{table}

\end{document} 

在此处输入图片描述

相关内容