表格内的标题

表格内的标题

大家好,有什么建议可以复制此表并包含标题组吗?这里有一个标题和我的代码

代码:

   \documentclass[a4paper, 12pt]{article} 
     \usepackage[margin=2cm]{geometry}
     \usepackage{booktabs} 
     \usepackage{amsmath}
     \usepackage{amsthm} 
     \usepackage{eucal}
     \usepackage{mathrsfs}
     \usepackage{lmodern}
    \usepackage{textcomp}
     \usepackage[utf8]{inputenc}                        
    \usepackage[T1]{fontenc}
    \usepackage[english]{babel}
    \usepackage{graphicx}
    \usepackage{amssymb}
    \usepackage{mathtools}
    \usepackage{multirow}
    \usepackage{array}
    %\usepackage[latin1]{inputenc}
    \usepackage{tabulary}
    \usepackage{tabularx}
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     \newcommand\mc[1]{\multicolumn{1}{c}{\scriptsize #1}}
     \newcolumntype{P}{>{\raggedright\scriptsize}p{4.0cm}}
      \newcolumntype{R}{*{11}{>{\scriptsize}c}}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \usepackage{dcolumn}
    \newcolumntype{d}[1]{D..{#1}} 
    %% \newcommand\mc[1]{\multicolumn{1}{c}{#1}}
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{document} 
 \begin{table}[!h]
  \caption{Daily returns summary statistics (whole sample).}
  \label{tab1}
    \begin{tabular}{@{}P@{\kern-30pt}R@{}}\toprule 
    \texttt{Commodity} 
 & \mc{No of observations}              
 &\mc{Mean}
 &\mc{Median}
 &\mc{S. dev.}
 &\mc{Min}&\mc{Max}
 &\mc{Kurtosis}
 &\mc{Skewness}
 &\mc{ShapiroWilk}
 &\mc{Ljung Box}\\[-2pt]
 \cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(lr){5-5} \cmidrule(lr) {6-6}  
 \cmidrule(lr) {7-7} \cmidrule(lr) {8-8}\cmidrule(lr) {9-9}
 \cmidrule(lr) {10-10}\cmidrule(lr) {11-11}
  Oil    & 520 & 0.008  & 0.000 & 0.099  & -0.540&1.154 &3.056 &42.226 &0.000&0.514\\ 
  Gas    &520  & 0.005  &0.000  & 0.057  &-0.329 &0.463 &1.650 &21.181 & 0.000&0.000  \\ 
  Electricity\newline   &520    &0.006   &0.000  &0.107 &-0.405& 0.478& 0.000&6.647 & 0.000&0.000\\ 
     [-8pt]
    Gold  &520 & 0.003& 0.000& 0.065& -0.278& 0.311& 0.326& 5.490& 0.000& 0.000     \\
    Silver& 520& 0.004& 0.002& 0.067& -0.279& 0.287& 0.125& 6.206& 0.000& 0.000\\
    Platinum &520& 0.003& 0.000& 0.058& -0.245& 0.298& -0.028& 5.907& 0.000& 0.509\\
    Palladium &520& 0.003& 0.000& 0.061& -0.278& 0.342& 0.193& 6.725& 0.000& 0.141\\
   Cotton &520& 0.003& 0.000& 0.064& -0.242& 0.582& 2.326& 20.935& 0.000& 0.000\\
   Lumber &520& 0.003& 0.000& 0.061& -0.219& 0.519& 1.406& 13.545& 0.000& 0.014\\
  \bottomrule %
  \end{tabular}
  \end{table}
 \end{document}

标题 :

在此处输入图片描述

答案1

以下可能更接近预期的输出。对于第一列中的“组”标题,我使用了\multicolumn{3}{@{}l}{...}以使文本更靠近表格的左边缘并节省一些空间。除此之外,我引入了siunitx以改善数字的对齐和负数的表示。此外,我使用了\thead来自makecell作为各个列标题。我还增加了字体大小并稍微更改了值以\tabcolsep确保表格适合文本宽度。我还提供了一个表格版本,其中第一列的布局不同,字体大小略小。最后,我删除了所有与表格无关/不再需要的包和定义。

在此处输入图片描述

\documentclass[a4paper, 12pt]{article} 
\usepackage[margin=2cm]{geometry}
\usepackage{booktabs} 
\usepackage{makecell}
\usepackage{siunitx}

\begin{document} 
 \begin{table}[!h]
   \caption{Daily returns summary statistics (whole sample).}
   \label{tab1}
   \centering
   \setlength{\tabcolsep}{4.75pt}
   \begin{tabular}{l 
                   S[table-format=3] 
                   *{3}{S[table-format=1.3]}
                   S[table-format=-1.3]
                   S[table-format=1.3]
                   S[table-format=-1.3]
                   S[table-format=2.3]
                   *{2}{S[table-format=1.3]}
                   }
     \toprule 
     \texttt{Commodity} 
     & {\thead{No of\\ observ.}}              
     &{\thead{Mean}}
     &{\thead{Median}}
     &{\thead{S. dev.}}
     &{\thead{Min}}
     &{\thead{Max}}
     &{\thead{Kurtosis}}
     &{\thead{Skewness}}
     &{\thead{Shapiro\\Wilk}}
     &{\thead{Ljung\\ Box}}\\
     \cmidrule(lr){2-2}   \cmidrule(lr){3-3}   \cmidrule(lr){4-4} \cmidrule(lr){5-5} 
     \cmidrule(lr){6-6}   \cmidrule(lr){7-7}   \cmidrule(lr){8-8} \cmidrule(lr){9-9}
     \cmidrule(lr){10-10} \cmidrule(lr){11-11}
     \multicolumn{3}{@{}l}{Energy group}\\
       Oil    & 520 & 0.008  & 0.000 & 0.099  & -0.540&1.154 &3.056 &42.226 &0.000&0.514\\ 
       Gas    &520  & 0.005  &0.000  & 0.057  &-0.329 &0.463 &1.650 &21.181 & 0.000&0.000  \\ 
       Electricity   &520    &0.006   &0.000  &0.107 &-0.405& 0.478& 0.000&6.647 & 0.000&0.000\\ 
     \multicolumn{3}{@{}l}{Precious metals group}\\
       Gold  &520 & 0.003& 0.000& 0.065& -0.278& 0.311& 0.326& 5.490& 0.000& 0.000     \\
       Silver& 520& 0.004& 0.002& 0.067& -0.279& 0.287& 0.125& 6.206& 0.000& 0.000\\
       Platinum &520& 0.003& 0.000& 0.058& -0.245& 0.298& -0.028& 5.907& 0.000& 0.509\\
       Palladium &520& 0.003& 0.000& 0.061& -0.278& 0.342& 0.193& 6.725& 0.000& 0.141\\
     \multicolumn{3}{@{}l}{Agricultural group}\\
       Cotton &520& 0.003& 0.000& 0.064& -0.242& 0.582& 2.326& 20.935& 0.000& 0.000\\
       Lumber &520& 0.003& 0.000& 0.061& -0.219& 0.519& 1.406& 13.545& 0.000& 0.014\\
     \bottomrule %
    \end{tabular}
 \end{table}
 
 
  \begin{table}[!h]
   \caption{Daily returns summary statistics (whole sample).}
   \label{tab1}
   \centering
   \small
   \setlength{\tabcolsep}{3pt}
   \begin{tabular}{l 
                   S[table-format=3] 
                   *{3}{S[table-format=1.3]}
                   S[table-format=-1.3]
                   S[table-format=1.3]
                   S[table-format=-1.3]
                   S[table-format=2.3]
                   *{2}{S[table-format=1.3]}
                   }
     \toprule 
     \texttt{Commodity} 
     & {\thead{No of\\ observ.}}              
     &{\thead{Mean}}
     &{\thead{Median}}
     &{\thead{S. dev.}}
     &{\thead{Min}}
     &{\thead{Max}}
     &{\thead{Kurtosis}}
     &{\thead{Skewness}}
     &{\thead{Shapiro\\Wilk}}
     &{\thead{Ljung\\ Box}}\\
     \cmidrule(lr){2-2}   \cmidrule(lr){3-3}   \cmidrule(lr){4-4} \cmidrule(lr){5-5} 
     \cmidrule(lr){6-6}   \cmidrule(lr){7-7}   \cmidrule(lr){8-8} \cmidrule(lr){9-9}
     \cmidrule(lr){10-10} \cmidrule(lr){11-11}
     \multicolumn{1}{@{}l}{Energy group}\\
       Oil    & 520 & 0.008  & 0.000 & 0.099  & -0.540&1.154 &3.056 &42.226 &0.000&0.514\\ 
       Gas    &520  & 0.005  &0.000  & 0.057  &-0.329 &0.463 &1.650 &21.181 & 0.000&0.000  \\ 
       Electricity   &520    &0.006   &0.000  &0.107 &-0.405& 0.478& 0.000&6.647 & 0.000&0.000\\ 
     \multicolumn{1}{@{}l}{Precious metals group}\\
       Gold  &520 & 0.003& 0.000& 0.065& -0.278& 0.311& 0.326& 5.490& 0.000& 0.000     \\
       Silver& 520& 0.004& 0.002& 0.067& -0.279& 0.287& 0.125& 6.206& 0.000& 0.000\\
       Platinum &520& 0.003& 0.000& 0.058& -0.245& 0.298& -0.028& 5.907& 0.000& 0.509\\
       Palladium &520& 0.003& 0.000& 0.061& -0.278& 0.342& 0.193& 6.725& 0.000& 0.141\\
     \multicolumn{1}{@{}l}{Agricultural group}\\
       Cotton &520& 0.003& 0.000& 0.064& -0.242& 0.582& 2.326& 20.935& 0.000& 0.000\\
       Lumber &520& 0.003& 0.000& 0.061& -0.219& 0.519& 1.406& 13.545& 0.000& 0.014\\
     \bottomrule %
    \end{tabular}
 \end{table}
\end{document}

答案2

变体布局和一些代码简化:现在,您不必加载inputenc选项,utf8因为它是默认选项。此外,您不必加载amsmath when you loadmathtools,因为后者会为您完成此操作。

\documentclass[a4paper, 12pt]{article}
 \usepackage[margin=2cm]{geometry}
 \usepackage{amsthm}
 \usepackage{eucal}
 \usepackage{mathrsfs}
 \usepackage{lmodern}
\usepackage{textcomp}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{siunitx} 
\usepackage[svgnames, table]{xcolor} 
\usepackage{caption, booktabs, makecell, eqparbox}
\usepackage{multirow}
\usepackage{array}

\usepackage{tabulary}
\usepackage{tabularx}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \newcommand\mc[1]{\multicolumn{1}{c}{\scriptsize #1}}
 \newcolumntype{P}{>{\raggedright}p{4.0cm}}
  \newcolumntype{R}{c*{3}{S}S[table-format=-1.3]SS[table-format=-1.3]S[table-format=2.3]SS}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{document}

 \begin{table}[!h]
  \caption{Daily returns summary statistics (whole sample).}
  \label{tab1}
\sisetup{table-format=1.3, table-number-alignment=center}
\setlength{\tabcolsep}{3pt}
\setlength{\cmidrulekern}{3pt}
\small
    \begin{tabular}{@{}l@{\quad}lR@{}}\toprule
   & \texttt{Commodity}
  & \makecell[b]{No of\\ observations}
 &{Mean}
 &{Median}
 &{S. dev.}
 &{Min}&{Max}
 &{Kurtosis}
 &{Skewness}
 &{\makecell[b]{Shapiro\\Wilk}}
 &{\makecell[b]{Ljung\\ Box}}\\[-2pt]
 \cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(lr){5-5} \cmidrule(lr) {6-6}
 \cmidrule(lr) {7-7} \cmidrule(lr) {8-8}\cmidrule(lr) {9-9}
 \cmidrule(lr) {10-10}\cmidrule(lr) {11-11}\cmidrule(lr) {12-12}
 \rlap{\colorbox{WhiteSmoke!80!Lavender}{\eqmakebox[H][l]{Energy group}}}\\
  & Oil & 520 & 0.008 & 0.000 & 0.099 & -0.540&1.154 &3.056 &42.226 &0.000&0.514\\
   & Gas &520 & 0.005 &0.000 & 0.057 &-0.329 &0.463 &1.650 &21.181 & 0.000&0.000 \\
  & Electricity &520 &0.006 &0.000 &0.107 &-0.405& 0.478& 0.000&6.647 & 0.000&0.000\\
\addlinespace
 \rlap{\colorbox{WhiteSmoke!80!Lavender}{\eqmakebox[H][l]{Precious metals group}}}\\%
   & Gold &520 & 0.003& 0.000& 0.065& -0.278& 0.311& 0.326& 5.490& 0.000& 0.000 \\
   & Silver& 520& 0.004& 0.002& 0.067& -0.279& 0.287& 0.125& 6.206& 0.000& 0.000\\
    & Platinum &520& 0.003& 0.000& 0.058& -0.245& 0.298& -0.028& 5.907& 0.000& 0.509\\
     & Palladium &520& 0.003& 0.000& 0.061& -0.278& 0.342& 0.193& 6.725& 0.000& 0.141\\
\addlinespace
 \rlap{\colorbox{WhiteSmoke!80!Lavender}{\eqmakebox[H][l]{Agricultural group}}}\\
    & Cotton &520& 0.003& 0.000& 0.064& -0.242& 0.582& 2.326& 20.935& 0.000& 0.000\\
    & Lumber &520& 0.003& 0.000& 0.061& -0.219& 0.519& 1.406& 13.545& 0.000& 0.014\\
  \bottomrule %
  \end{tabular}
  \end{table}

 \end{document} 

在此处输入图片描述

相关内容