TransWikia.com

substack in multirow table gives error

TeX - LaTeX Asked on January 17, 2021

I am using a multi-row table to display result. I want to break the table content text, for that, I am using substack but I keep getting an error

enter image description here

begin{table*}
    small
centering
begin{tabular}{c | c|ccccc}
    toprule
cmidrule(lr){5-7}&  &textbf{F1-score}  &  textbf{Precision}  & textbf{Sensitivity}  & textbf{Specificity}  & textbf{Accuracy}          
    midrule
    multirow{4}{*}{substack{text{ textbf{Using model A}}  text{textbf{data Only}}}}

        & footnotesize class A    & footnotesize 90.6 $pm$ 0.2% &  footnotesize 89.1 $pm$ 0.4% & footnotesize 86.2 $pm$ 0.3% & footnotesize 92.4 $pm$ 0.2%& footnotesize 89.3 $pm$ 0.1%
        & footnotesize class B   & footnotesize 90.6 $pm$ 0.1% & footnotesize 91.7 $pm$ 0.1% & footnotesize 94.3 $pm$ 0.3%& footnotesize 89.3 $pm$ 0.1% &footnotesize 92.4 $pm$ 0.1%            
        cmidrule{2-7}
        & footnotesize Overall & footnotesize 90.6 $pm$ 0.3% & footnotesize 90.4 $pm$ 0.5% & footnotesize 90.1 $pm$ 0.6% & footnotesize 90.3 $pm$ 0.3% & footnotesize 90.8 $pm$ 0.2%
        
        cmidrule{2-7}
multirow{4}{*}{substack{text{ textbf{Using Model B}}  text{textbf{data only}}}}

       & footnotesize class A    & footnotesize 91.5 $pm$ 0.2% & footnotesize 86.9 $pm$ 0.5% & footnotesize 87.8 $pm$ 0.2% & footnotesize 86.0 $pm$ 0.3% & footnotesize 94.1 $pm$ 0.6%           
        & footnotesize class B    & footnotesize 91.5 $pm$ 0.1% & footnotesize 93.7 $pm$ 0.3% & footnotesize 93.3 $pm$ 0.2% & footnotesize 94.1 $pm$ 0.1% & footnotesize 86.0 $pm$ 0.2%
        cmidrule{2-7}
        & footnotesize Overall   & footnotesize 91.5 $pm$ 0.3%& footnotesize 90.3 $pm$ 0.8%& footnotesize 90.5 $pm$ 0.4%& footnotesize 90.8 $pm$ 0.3%&footnotesize  91.1 $pm$ 0.8%
    cmidrule{2-7}
    multirow{4}{*}{substack{text{ textbf{Using Both}}  text{textbf{data}}}}
       & footnotesize class A    & footnotesize 96.8  $pm$ 0.4% &footnotesize 95.1 $pm$ 0.1%&footnotesize 94.6 $pm$ 0.3%&footnotesize 95.6 $pm$ 0.1%&footnotesize 97.3 $pm$ 0.2%           
        & footnotesize class B   & footnotesize 96.8 $pm$ 0.1% &footnotesize 97.6 $pm$ 0.3% & footnotesize 97.8 $pm$ 0.4% &footnotesize 97.3 $pm$ 0.2%& footnotesize 95.6 $pm$ 0.3% 
        cmidrule{2-7}
        & footnotesize Overall & footnotesize 96.8 $pm$ 0.5% &footnotesize 96.3 $pm$ 0.4%&footnotesize 96.2 $pm$ 0.7%&footnotesize 96.5 $pm$ 0.3%&footnotesize 96.5 $pm$ 0.5%
        
    bottomrule
end{tabular}
caption{ Model performance metrics across different models on data }
label{tab:allcls}
    end{table*}

My table looks like this:

enter image description here

If I am not using subtask, then the error is gone but Then How to break the text like in the image?

Thank you!

3 Answers

What you are looking for is makecell

add the following in the preamble

usepackage{multirow, makecell}

and in your multirow command replace with the following

multirowcell{4}{Using Model A Data Only}

and you will get

enter image description here

MWE

documentclass[10pt,a4paper]{article}

usepackage{booktabs}
usepackage{siunitx}
usepackage{multirow, makecell}
begin{document}
begin{table*}

small
centering
begin{tabular}{c | c|ccccc}
    toprule
    &  &textbf{F1-score}  &  textbf{Precision}  & textbf{Sensitivity}  & 
    textbf{Specificity}  & textbf{Accuracy}          
    midrule
    multirowcell{4}{Using Model A Data Only}
    
    & footnotesize class A    & footnotesize 90.6 $pm$ 0.2% &  
      footnotesize 89.1 $pm$ 0.4% & footnotesize 86.2 $pm$ 0.3% & 
     footnotesize 92.4 $pm$ 0.2%& footnotesize 89.3 $pm$ 0.1%
    & footnotesize class B   & footnotesize 90.6 $pm$ 0.1% & 
    footnotesize 91.7 $pm$ 0.1% & footnotesize 94.3 $pm$ 0.3%& 
     footnotesize 89.3 $pm$ 0.1% &footnotesize 92.4 $pm$ 0.1%            
     
    cmidrule{2-7}
    & footnotesize Overall & footnotesize 90.6 $pm$ 0.3% & footnotesize 
    90.4 $pm$ 0.5% & footnotesize 90.1 $pm$ 0.6% & footnotesize 90.3 
    $pm$ 0.3% & footnotesize 90.8 $pm$ 0.2%
    
    cmidrule{2-7}
    multirowcell{4}{Using Model A Data Only}
    
    & footnotesize class A    & footnotesize 91.5 $pm$ 0.2% & 
       footnotesize 86.9 $pm$ 0.5% & footnotesize 87.8 $pm$ 0.2% & 
     footnotesize 86.0 $pm$ 0.3% & footnotesize 94.1 $pm$ 0.6%           
      
    & footnotesize class B    & footnotesize 91.5 $pm$ 0.1% & 
       footnotesize 93.7 $pm$ 0.3% & footnotesize 93.3 $pm$ 0.2% & 
      footnotesize 94.1 $pm$ 0.1% & footnotesize 86.0 $pm$ 0.2%
    cmidrule{2-7}
    & footnotesize Overall   & footnotesize 91.5 $pm$ 0.3%& footnotesize 
     90.3 $pm$ 0.8%& footnotesize 90.5 $pm$ 0.4%& footnotesize 90.8 
     $pm$ 0.3%&footnotesize  91.1 $pm$ 0.8%
    cmidrule{2-7}
    multirowcell{4}{Using Model A Data Only}
    & footnotesize class A    & footnotesize 96.8  $pm$ 0.4% 
    &footnotesize 95.1 $pm$ 0.1%&footnotesize 94.6 $pm$ 
      0.3%&footnotesize 95.6 $pm$ 0.1%&footnotesize 97.3 $pm$ 0.2%           
     
    & footnotesize class B   & footnotesize 96.8 $pm$ 0.1% &footnotesize 
    97.6 $pm$ 0.3% & footnotesize 97.8 $pm$ 0.4% &footnotesize 97.3 
     $pm$ 0.2%& footnotesize 95.6 $pm$ 0.3% 
    cmidrule{2-7}
    & footnotesize Overall & footnotesize 96.8 $pm$ 0.5% &footnotesize 
   96.3 $pm$ 0.4%&footnotesize 96.2 $pm$ 0.7%&footnotesize 96.5 $pm$ 
     0.3%&footnotesize 96.5 $pm$ 0.5%
    
    bottomrule
end{tabular}
caption{ Model performance metrics across different models on data }
label{tab:allcls}
 end{table*}
 end{document}

PS --I have also removed cmidrule in the first line of the table since it is redundant

Answered by js bibra on January 17, 2021

I suggest the following redesign without multirow and vertical lines (the latter are incompatible with horizontal lines from the booktabs package, such as toprule):

enter image description here

documentclass[twocolumn]{article}
usepackage{booktabs}


begin{document}

begin{table*}

centering
begin{tabular}{lccccc}
    toprule
  & F1-score  &  Precision  & Sensitivity  & Specificity  & Accuracy          
    midrule
    multicolumn{6}{@{}l}{Using model A data Only}
    addlinespace
          class A    &  90.6 $pm$ 0.2% &   89.1 $pm$ 0.4% &  86.2 $pm$ 0.3% &  92.4 $pm$ 0.2%&  89.3 $pm$ 0.1%
          class B   &  90.6 $pm$ 0.1% &  91.7 $pm$ 0.1% &  94.3 $pm$ 0.3%&  89.3 $pm$ 0.1% & 92.4 $pm$ 0.1%            

          Overall &  90.6 $pm$ 0.3% &  90.4 $pm$ 0.5% &  90.1 $pm$ 0.6% &  90.3 $pm$ 0.3% &  90.8 $pm$ 0.2%
        
midrule
multicolumn{6}{@{}l}{Using Model B data only}
addlinespace
         class A    &  91.5 $pm$ 0.2% &  86.9 $pm$ 0.5% &  87.8 $pm$ 0.2% &  86.0 $pm$ 0.3% &  94.1 $pm$ 0.6%           
          class B    &  91.5 $pm$ 0.1% &  93.7 $pm$ 0.3% &  93.3 $pm$ 0.2% &  94.1 $pm$ 0.1% &  86.0 $pm$ 0.2%
%        cmidrule{2-7}
          Overall   &  91.5 $pm$ 0.3%&  90.3 $pm$ 0.8%&  90.5 $pm$ 0.4%&  90.8 $pm$ 0.3%&  91.1 $pm$ 0.8%
midrule
    multicolumn{6}{@{}l}{Using Both data}
    addlinespace
         class A    &  96.8  $pm$ 0.4% & 95.1 $pm$ 0.1%& 94.6 $pm$ 0.3%& 95.6 $pm$ 0.1%& 97.3 $pm$ 0.2%           
          class B   &  96.8 $pm$ 0.1% & 97.6 $pm$ 0.3% &  97.8 $pm$ 0.4% & 97.3 $pm$ 0.2%&  95.6 $pm$ 0.3% 
%        cmidrule{2-7}
          Overall &  96.8 $pm$ 0.5% & 96.3 $pm$ 0.4%& 96.2 $pm$ 0.7%& 96.5 $pm$ 0.3%& 96.5 $pm$ 0.5%
        
    bottomrule
end{tabular}
caption{ Model performance metrics across different models on data }
label{tab:allcls}
    end{table*}


end{document}

Answered by leandriis on January 17, 2021

With use of siunitx:

documentclass[twocolumn]{article}
usepackage{booktabs}
newcommandmcc[1]{multicolumn{1}{c}{#1}}
newcommandmcl[1]{multicolumn{6}{@{} l}{#1}}
usepackage{siunitx}

begin{document}
    begin{table*}
    centering
    %setlengthtabcolsep{1pt}
    sisetup{table-format=2.1(2),
             table-space-text-post={,%},   
             separate-uncertainty}
begin{tabular}{l *{5}{S<{,%}} }
    toprule
        & mcc{F1-score} 
                    & mcc{Precision}  
                                & mcc{Sensitivity} 
                                            & mcc{Specificity} 
                                                        & mcc{Accuracy}
    midrule
mcl{Using model A data Only}                                           
    addlinespace
class A & 90.6(2)   & 89.1(4)   & 86.2(3)   & 92.4(2)   & 89.3(1)       cr
class B &  90.6(1)  &  91.7(1)  &  94.3(3)  & 89.3(1)   & 92.4(1)       cr
Overall &  90.6(3)  &  90.4(5)  &  90.1(6)  &  90.3(3)  &  90.8(2)      cr
    midrule
mcl{Using Model B data only}                                           
    addlinespace
class A &  91.5(2)  &  86.9(5)  &  87.8(2)  &  86.0(3)  &  94.1(6)      cr
class B &  91.5(1)  &  93.7(3)  &  93.3(2)  &  94.1(1)  &  86.0(2)      cr
Overall &  91.5(3)  &  90.3(8)  &  90.5(4)  &  90.8(3)  &  91.1(8)      cr
    midrule
mcl{Using Both data}
    addlinespace
class A &  96.8(4)  &  95.1(1)  &  94.6(3)   & 95.6(1)  &  97.3(2)      cr
class B &  96.8(1)  &  97.6(3)  &  97.8(4)   & 97.3(2)  &  95.6(3)      cr
Overall &  96.8(5)  &  96.3(4)  &  96.2(7)   & 96.5(3)  &  96.5(5)      cr
    bottomrule
end{tabular}
caption{ Model performance metrics across different models on data}
label{tab:allcls}
    end{table*}
end{document}

enter image description here

Answered by Zarko on January 17, 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