TransWikia.com

fixing headers and column table

TeX - LaTeX Asked on May 26, 2021

Hi I have used a recent suggestion by @leandriis to fix the headers table, but when I tried to use his suggestion to draw another table, I’m getting several issues, here my suggestion, my output and the desired table to produce.

My suggestion :

    documentclass{article}
    usepackage{geometry}
    usepackage{rotating}
    usepackage{booktabs, makecell}
    usepackage[referable]{threeparttablex}
    usepackage{siunitx}
   usepackage[skip=1ex]{caption}
   usepackage{xcolor}
   newcommandtc[1]{textcolor{blue}{#1}}
   NewExpandableDocumentCommandmcc{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.42tc{**} & 0.01& 0.65& 3.54tc{**} & 0.00 
        Median          & 0.32& 2.38tc{**} & 0.01& 0.68& 3.77tc{**} & 0.00 
        Trimmed mean    & 0.34& 2.39tc{**} & 0.01& 0.66& 3.67tc{**} & 0.00
        DMSE,$Psi=1.00$& 0.35& 2.42tc{**} & 1.00& 1.10& 3.54tc{**} & 0.00
        DMSE,$Psi=0.90$& 0.35& 2.41tc{**} & 1.00& 1.10& 3.55tc{**} & 0.00
        C(2, PB)        & 0.34& 2.34tc{**} & 0.01& 0.66& 3.59tc{**} & 0.00
        C(2, PB)        & 0.36& 2.33tc{**} & 0.01& 0.64& 3.43tc{**} & 0.00
        PC              & 0.59& 2.79tc{**} & 0.00& 0.41& 2.14tc{**} & 1.00             
  bottomrule
end{tabular}
 end{threeparttable}
 end{table}
 end{document}

my output:

enter image description here

Desired Table :

enter image description here

One Answer

In the following MWE, I first of all made sure, the code is compilable. Your original code was not compilable and resulted in a bunch of error messages due to various syntax errors. As soon as you get an error message, do not look as the resulting pdf file, but fiy the error mesages first. If you can't ask a specific question about this error message, but don't ignore them.

I added some small comments regarding all the changes I made to your code hoping that this will help you understand the reason for all these changes.

enter image description here

documentclass{article}
usepackage{geometry}
usepackage{rotating}
usepackage{booktabs, makecell}
usepackage[referable]{threeparttablex}
usepackage{siunitx}
usepackage[skip=1ex]{caption}
usepackage{xcolor}
newcommandtc[1]{textcolor{blue}{#1}}
NewExpandableDocumentCommandmcc{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.42tc{**} & 0.01& 0.65& 3.54tc{**} & 0.00 
 Median          &      & 0.32 & 2.38tc{**} & 0.01& 0.68& 3.77tc{**} & 0.00 
 Trimmed mean    &      & 0.34 & 2.39tc{**} & 0.01& 0.66& 3.67tc{**} & 0.00
 DMSE,$Psi=1.00$&      & 0.35 & 2.42tc{**} & 1.00& 1.10& 3.54tc{**} & 0.00
 DMSE,$Psi=0.90$&      & 0.35 & 2.41tc{**} & 1.00& 1.10& 3.55tc{**} & 0.00
 C(2, PB)        &      & 0.34 & 2.34tc{**} & 0.01& 0.66& 3.59tc{**} & 0.00
 C(2, PB)        &      & 0.36 & 2.33tc{**} & 0.01& 0.64& 3.43tc{**} & 0.00
 PC              &      & 0.59 & 2.79tc{**} & 0.00& 0.41& 2.14tc{**} & 1.00             
  bottomrule
end{tabular}
 end{threeparttable}
 end{table}
 end{document}

Correct answer by leandriis on May 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP