TransWikia.com

add a line in multicolumn

TeX - LaTeX Asked on August 12, 2021

I have a table that looks as follows and I want to add a row Income 2 properly enter image description hereshown in the photo, many thanks in advance. The code was taken from Here.

    documentclass[11pt,authoryear,sort&compress]{report}
usepackage{booktabs,tabulary,array,tabularx}
usepackage{geometry}
newcolumntype{z}{>{arraybackslashcentering}X}
begin{document}
    begin{table}
        caption{Sample description.}
        centering
        begin{tabularx}{linewidth}{p{2cm}XcXc}  
            toprule
            Variable   &  multicolumn{4}{c}{Factor} cmidrule(rl){1-1}cmidrule(rl){2-5}    
            & multicolumn{2}{c}{0} & multicolumn{2}{c}{1}   
            cmidrule(rl){2-3}cmidrule(rl){4-5} 
            Gender & Female dotfill & 21.27 % & Male dotfill & 78.73 %  
            Married & Others dotfill & 10.80 % & Married/Cohabited dotfill & 89.20 % addlinespace[1em]
            
            Region & multicolumn{4}{l}
            {begin{tabularx}{dimexprlinewidth-2cm-4tabcolsep}{zzz}  
                    West & East & Center tabularnewline
                    cmidrule(r){1-1}cmidrule(rl){2-2}cmidrule(l){3-3} 
                    27.7 %  & 41.1 %  & 30.2 % tabularnewlineend{tabularx}}
            addlinespace[1em]

         Income 1 & multicolumn{4}{c}
            {begin{tabularx}{dimexprlinewidth-2cm-4tabcolsep}{zzzzzzz}  
                    multicolumn{7}{c}{normalsize Continuous}tabularnewlinemidrule
                Mean & SD & Median & Min &  Max & Skew & Kurt tabularnewlinemidrule
                77263.25  &197349.48  &45575.00  &109.00  &5000000 &16.30   &347.98 tabularnewlineend{tabularx}}
            addlinespace[1em]
            
            Income 2  & multicolumn{4}{c}
            {begin{tabularx}{dimexprlinewidth-2cm-4tabcolsep}{zzzzzzz}  
                    %multicolumn{7}{c}{normalsize Continuous}tabularnewlinemidrule
                    %Mean & SD & Median & Min &  Max & Skew & Kurt tabularnewlinemidrule
                    77263.25  &197349.48  &45575.00  &109.00  &5000000 &16.30   &347.98 
            tabularnewlineaddlinespace[1em] 
                end{tabularx}  

    }bottomrule
        end{tabularx}   
    end{table}
end{document}

2 Answers

You can make three tables.

documentclass[11pt,authoryear,sort&compress]{report}
usepackage{booktabs,tabulary,array,tabularx}
usepackage{geometry}

newcolumntype{z}{>{centeringarraybackslash}X}

begin{document}

begin{table}
centering

caption{Sample description.}

begin{tabularx}{linewidth}{@{}p{2cm}XcXc@{}}
toprule
Variable   &  multicolumn{4}{c}{Factor} 
cmidrule(r){1-1} cmidrule(l){2-5}    
           & multicolumn{2}{c}{0} & multicolumn{2}{c}{1}   
cmidrule(rl){2-3}cmidrule(l){4-5} 
Gender  & Female dotfill & 21.27 % & Male dotfill              & 78.73 %  
Married & Others dotfill & 10.80 % & Married/Cohabited dotfill & 89.20 % 
end{tabularx}

vspace{1ex}

makebox[dimexpr 2cm+2tabcolsep][l]{Region}%
begin{tabularx}{dimexprlinewidth-2cm-2tabcolsep}{@{}zzz@{}}
West & East & Center 
cmidrule(r){1-1}cmidrule(rl){2-2}cmidrule(l){3-3} 
27.7 %  & 41.1 %  & 30.2 % 
end{tabularx}

vspace{1ex}

begin{tabular*}{linewidth}{@{}p{dimexpr 2cm+tabcolsep}@{extracolsep{fill}}*{7}{c}@{}}
& multicolumn{7}{c}{normalsize Continuous}
cmidrule{2-8}
& Mean & SD & Median & Min &  Max & Skew & Kurt 
cmidrule{2-8}
Income 1 & 77263.25  &197349.48  &45575.00  &109.00  &5000000 &16.30   &347.98 
Income 2 & 77263.25  &197349.48  &45575.00  &109.00  &5000000 &16.30   &347.98 
bottomrule
end{tabular*}

end{table}

end{document}

enter image description here

Correct answer by egreg on August 12, 2021

Probably you're interested in the following output:

enter image description here

    documentclass[11pt,authoryear,sort&compress]{report}
usepackage{booktabs,tabulary,array,tabularx}
usepackage{geometry}
newcolumntype{z}{>{arraybackslashcentering}X}
begin{document}
    begin{table}
        caption{Sample description.}
        centering
        begin{tabularx}{linewidth}{p{2cm}XcXc}  
            toprule
            Variable   &  multicolumn{4}{c}{Factor} cmidrule(rl){1-1}cmidrule(rl){2-5}    
            & multicolumn{2}{c}{0} & multicolumn{2}{c}{1}   
            cmidrule(rl){2-3}cmidrule(rl){4-5} 
            Gender & Female dotfill & 21.27 % & Male dotfill & 78.73 %  
            Married & Others dotfill & 10.80 % & Married/Cohabited dotfill & 89.20 % addlinespace[1em]
            
            Region & multicolumn{4}{l}
            {begin{tabularx}{dimexprlinewidth-2cm-4tabcolsep}{zzz}  
                    West & East & Center tabularnewline
                    cmidrule(r){1-1}cmidrule(rl){2-2}cmidrule(l){3-3} 
                    27.7 %  & 41.1 %  & 30.2 % tabularnewlineend{tabularx}}
            addlinespace[1em]

          & multicolumn{4}{c}
            {begin{tabularx}{dimexprlinewidth-2cm-4tabcolsep}{zzzzzzz}  
                    multicolumn{7}{c}{normalsize Continuous}tabularnewlinemidrule
                Mean & SD & Median & Min &  Max & Skew & Kurt tabularnewlinemidrule end{tabularx}}
            
            Income 1 & multicolumn{4}{c}
            {begin{tabularx}{dimexprlinewidth-2cm-4tabcolsep}{zzzzzzz}                  77263.25  &197349.48  &45575.00  &109.00  &5000000 &16.30   &347.98
            end{tabularx}}

            Income 2 & multicolumn{4}{c}
            {begin{tabularx}{dimexprlinewidth-2cm-4tabcolsep}{zzzzzzz}                  77263.25  &197349.48  &45575.00  &109.00  &5000000 &16.30   &347.98
            end{tabularx}}

    bottomrule
        end{tabularx}   
    end{table}
end{document}

Answered by leandriis on August 12, 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