2

taking the code from Here and Here but I can not fit it to the page properly enter image description here.

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

\newcolumntype{z}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}
\centering

\caption{Sample description.}

\begin{tabularx}{\linewidth}{@{}p{2.5cm}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 \% \\
Employed & Others \dotfill & 34.02\%  &  Employed \dotfill & 65.98\% \\
Education & Others  \dotfill & 80.79\% & High-school or above \dotfill & 19.21\% \\
Party & Others      \dotfill & 81.89\% & Party       \dotfill & 18.11\% \\
HR    & Rural       \dotfill & 58.5\%  & Urban       \dotfill& 41.5\% \\
Access Loan & Others\dotfill & 73.69\% & Access Loan \dotfill & 26.31\% \\
Formal & Others     \dotfill & 91.95\% & Formal      \dotfill & 8.05\% \\
Informal & Others   \dotfill & 85.26\% & Informal    \dotfill & 14.74\% \\
Both & Others       \dotfill & 96.48\% & Both        \dotfill & 3.52\% \\
No Loans & Others   \dotfill & 26.31\% & No loans    \dotfill& 73.69\% \\ %\addlinespace[1em]

\end{tabularx}

\vspace{1ex}

\makebox[\dimexpr 2.5cm+2.5\tabcolsep][l]{Region}%
\begin{tabularx}{\dimexpr\linewidth-2.5cm-2.5\tabcolsep}{@{}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 2.5cm+\tabcolsep}@{\extracolsep{\fill}}*{7}{c}@{}}
& \multicolumn{7}{c}{\normalsize Continuous}\\
\cmidrule{2-8}
& Mean & SD & Median & Min &  Max & Skew & Kurt \\
\cmidrule{2-8}
Age    &     54.38      &13.39     &53.00       &18.00      &101  &0.12   & -0.47 \\
Income &  77263.25  &197349.48  &45575.00      &109.00  &5000000 &16.30   &347.98 \\
Networth & 836411.01 &1656146.88 &330972.64 &-3387183.98 &19941804  &5.76   & 47.37 \\
NW-HE & 254640.44 &1054721.27  &24363.09 &-5328515.56 &19747761 &10.01   &138.76 \\
Liquid Assets & 935052.61 &1744912.48 &405922.47     &1257.82 &20000000  &5.76   & 47.01 \\
\bottomrule
\end{tabular*}

\end{table}

\end{document}
2
  • 1
    Adding \setlength{\tabcolsep}{0pt} right before the last \begin{tabular*} should work. Alternatively, you could also decrease the font size in all tables, for example by adding \small before the first \begin{tabularx}.
    – leandriis
    Jan 6, 2021 at 13:02
  • 1
    Entirely unrelated, but sometimes thare is a space between the number and the % inside of the first tabularx, sometimes there is no space. You might want to unify that.
    – leandriis
    Jan 6, 2021 at 13:07

1 Answer 1

3

I think your best option is to use three separate tabular or tabularx environments.

I would also align the numbers in the data columns on their respective decimal separators.

enter image description here

\documentclass[11pt]{report}
\usepackage{booktabs,tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight\hangafter=1\hangindent=0.5em}X}
\usepackage{geometry}
\usepackage[group-digits=false]{siunitx}
\newcolumntype{T}[1]{S[table-format=#1]}

\begin{document}

\begin{table}
\caption{Sample description.}
\centering

\begin{tabularx}{\linewidth}{@{} X XrXr @{}}
\toprule
\addlinespace
&  \multicolumn{4}{c@{}}{Factor} \\
 \cmidrule(l){2-5}    
Variable & \multicolumn{2}{c}{0} & \multicolumn{2}{c@{}}{1}  \\
\cmidrule(r){1-1} \cmidrule(lr){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\% \\
Employed & Others \dotfill & 34.02\%   &  Employed \dotfill   & 65.98\% \\
Education & Others  \dotfill & 80.79\% & High-school or above \dotfill & 19.21\% \\
Party     & Others  \dotfill & 81.89\% & Party       \dotfill & 18.11\% \\
HR        & Rural   \dotfill & 58.50\% & Urban       \dotfill & 41.50\% \\
Access Loan & Others\dotfill & 73.69\% & Access Loan \dotfill & 26.31\% \\
Formal   & Others   \dotfill & 91.95\% & Formal      \dotfill & 8.05\% \\
Informal & Others   \dotfill & 85.26\% & Informal    \dotfill & 14.74\% \\
Both     & Others   \dotfill & 96.48\% & Both        \dotfill & 3.52\% \\
No Loans & Others   \dotfill & 26.31\% & No loans    \dotfill & 73.69\% 
\end{tabularx}

\vspace{3.5ex}

\begin{tabular}{@{} lccc @{}}
& West & East & Center \\
\cmidrule(l){2-4}
Region & 27.7\%  & 41.1\%  & 30.2\%
\end{tabular}

\vspace{3ex}

\setlength\tabcolsep{4pt}
\begin{tabularx}{\linewidth}{@{} L T{6.2} T{7.2} T{6.2} T{-7.2} T{8.0} T{2.2} T{3.2} @{} }
& \multicolumn{7}{c@{}}{Continuous}\\
\cmidrule(l){2-8}
& {Mean} & {SD} & {Median} & {Min} &  {Max} & {Skew} & {Kurt} \\
\cmidrule(l){2-8}
Age    &     54.38      &13.39     &53.00       &18.00      &101  &0.12   & -0.47 \\
Income &  77263.25  &197349.48  &45575.00      &109.00  &5000000 &16.30   &347.98 \\
Net worth& 836411.01 &1656146.88 &330972.64 &-3387183.98 &19941804  &5.76   & 47.37 \\
NW-HE & 254640.44 &1054721.27  &24363.09 &-5328515.56 &19747761 &10.01   &138.76 \\
Liquid Assets & 935052.61 &1744912.48 &405922.47 &1257.82 &20000000  &5.76   & 47.01 \\
\bottomrule
\end{tabularx}

\end{table}

\end{document}
1
  • 1
    I can't help but observe that the middle tabular environment is not at all clear. Aren't "West", "Center", and "East" also regions? Thus, why is the label "Region" affixed to the first row. Shouldn't the label be something like "Share" or "Percentage Share", especially as the numbers would add up to (close to) 100%?
    – Mico
    Jan 6, 2021 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .