修复标题和列表

修复标题和列表

你好,我使用了@leandriis 最近的建议来修复标题表,但是当我尝试使用他的建议来绘制另一个表格时,我遇到了几个问题,这是我的建议、我的输出和想要生成的表格。

我的建议 :

    \documentclass{article}
    \usepackage{geometry}
    \usepackage{rotating}
    \usepackage{booktabs, makecell}
    \usepackage[referable]{threeparttablex}
    \usepackage{siunitx}
   \usepackage[skip=1ex]{caption}
   \usepackage{xcolor}
   \newcommand\tc[1]{\textcolor{blue}{#1}}
   \NewExpandableDocumentCommand\mcc{O{1}m}
   {\multicolumn{#1}{>{\bfseries}c}{#2}}
   \usepackage{multirow}
   \renewcommand{\theadfont}{\normalsize} 

 \begin{document}
 \begin{table}[h!]
 \centering
 \begin{threeparttable}
  \caption{Forecasting and encompassing test results for the bagging model and combining methods, 
   1995:04–2005:03 out-of-sample period}
   \label{tab1}
   \begin{tabular}{@{} >{\itshape}l
               *{8}{S[table-format=1.2]}
                }
  \toprule
  \multirow{2.1}{*}{Combining method} 
  & \mcc[4]{$\thead{H_{0}$: BA encompasses CB}} 
  & \mcc[4]{$\thead{H_{0}$: CB encompasses BA}}   \\ 
  \cmidrule(r){2-5} \cmidrule(l){6-9}
  & \mcc{\hat{\lambda}_{CB}} & \mcc{MHLN_{h}} & \mcc{P-value} 
  & \mcc{\hat{\lambda}_{CB}} & \mcc{MHLN_{h}} & \mcc{P-value}\\
  \midrule
  BA model&9.13& & & & & \\
  Mean            & 0.35& 2.42\tc{**} & 0.01& 0.65& 3.54\tc{**} & 0.00\\ 
        Median          & 0.32& 2.38\tc{**} & 0.01& 0.68& 3.77\tc{**} & 0.00\\ 
        Trimmed mean    & 0.34& 2.39\tc{**} & 0.01& 0.66& 3.67\tc{**} & 0.00\\
        DMSE,$\Psi=1.00$& 0.35& 2.42\tc{**} & 1.00& 1.10& 3.54\tc{**} & 0.00\\
        DMSE,$\Psi=0.90$& 0.35& 2.41\tc{**} & 1.00& 1.10& 3.55\tc{**} & 0.00\\
        C(2, PB)        & 0.34& 2.34\tc{**} & 0.01& 0.66& 3.59\tc{**} & 0.00\\
        C(2, PB)        & 0.36& 2.33\tc{**} & 0.01& 0.64& 3.43\tc{**} & 0.00\\
        PC              & 0.59& 2.79\tc{**} & 0.00& 0.41& 2.14\tc{**} & 1.00\\             
  \bottomrule
\end{tabular}
 \end{threeparttable}
 \end{table}
 \end{document}

我的输出:

在此处输入图片描述

所需表格:

在此处输入图片描述

答案1

在以下 MWE 中,我首先确保代码是可编译的。您的原始代码不可编译,并由于各种语法错误导致一堆错误消息。一旦收到错误消息,请不要查看生成的 pdf 文件,而是先查看错误消息。如果您无法就此错误消息提出具体问题,但不要忽略它们。

我对对您的代码所做的所有更改添加了一些小注释,希望这可以帮助您理解所有这些更改的原因。

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage{rotating}
\usepackage{booktabs, makecell}
\usepackage[referable]{threeparttablex}
\usepackage{siunitx}
\usepackage[skip=1ex]{caption}
\usepackage{xcolor}
\newcommand\tc[1]{\textcolor{blue}{#1}}
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{>{\bfseries}c}{#2}}
\usepackage{multirow}
\renewcommand{\theadfont}{\normalsize} 

 \begin{document}
 \begin{table}[h!]
 \centering
 \sisetup{table-format=1.2, table-column-width=1cm} % added. Setting are applied to all S type columns in this particular table, made all S type columns slightly wider to avoid uneven column widths due to too long shared header
 \begin{threeparttable}
  \caption{Forecasting and encompassing test results for the bagging model and combining methods, 
   1995:04–2005:03 out-of-sample period}
   \label{tab1}
   \begin{tabular}{@{} >{\itshape}l
                       S  % suitable column type for the "MSFE" column
               *{2}{S S[table-space-text-post=\tc{**}] S} % added table-space-text-post option for all "MHLN" columns, since they not only contain numbers, but also asterisks. Added in order to avoid overfull boxes, to regular S type columns for the \labmda_CB and P value columns
                }
  \toprule
  % \multirow removed, moved text to next row
  & & \mcc[3]{$H_{0}$: BA encompasses CB}  % added another & here,  \thead reomved here sinye you don't need manual linebreaks here
  & \mcc[3]{$H_{0}$: CB encompasses BA}   \\  % \thead reomved here sinye you don't need manual linebreaks here
  \cmidrule(r){3-5} \cmidrule(l){6-8} % corrected \cmidrule commands.
 Combining method & {MSFE} & \mcc{$\hat{\lambda}_{CB}$} & \mcc{$MHLN_{h}$} & \mcc{P-value}   % added "Combining method"  and " MSFE & " here,  math mode ($...$) added since neither \lambda not _ for subscripts can be used in text mode. Do not ignore error messages!
  & \mcc{$\hat{\lambda}_{CB}$} & \mcc{$MHLN_{h}$} & \mcc{P-value}\\ % math mode ($...$) added since neither \lambda not _ for subscripts can be used in text mode. Do not ignore error messages!
  \midrule 
  \multicolumn{8}{c}{A. $h=1$}\\ % added \multicolumn[1}{c}  for horizontally centered text here
 BA model        & 0.90 & 9.13 & & & & & \\ % added MSFE column here
 Mean            &      & 0.35 & 2.42\tc{**} & 0.01& 0.65& 3.54\tc{**} & 0.00\\ 
 Median          &      & 0.32 & 2.38\tc{**} & 0.01& 0.68& 3.77\tc{**} & 0.00\\ 
 Trimmed mean    &      & 0.34 & 2.39\tc{**} & 0.01& 0.66& 3.67\tc{**} & 0.00\\
 DMSE,$\Psi=1.00$&      & 0.35 & 2.42\tc{**} & 1.00& 1.10& 3.54\tc{**} & 0.00\\
 DMSE,$\Psi=0.90$&      & 0.35 & 2.41\tc{**} & 1.00& 1.10& 3.55\tc{**} & 0.00\\
 C(2, PB)        &      & 0.34 & 2.34\tc{**} & 0.01& 0.66& 3.59\tc{**} & 0.00\\
 C(2, PB)        &      & 0.36 & 2.33\tc{**} & 0.01& 0.64& 3.43\tc{**} & 0.00\\
 PC              &      & 0.59 & 2.79\tc{**} & 0.00& 0.41& 2.14\tc{**} & 1.00\\             
  \bottomrule
\end{tabular}
 \end{threeparttable}
 \end{table}
 \end{document}

相关内容