1

I would be very appreciated if you can align the table. many thanks in advance.

\documentclass[11pt,authoryear,sort&compress]{report}
\usepackage{booktabs,tabulary,array,tabularx}
\usepackage{geometry}
\newcolumntype{z}{>{\centering\arraybackslash}X}
\begin{document}    
\begin{table}
    \centering
    \footnotesize
    %\setlength{\tabcolsep}{1pt}
    \begin{tabularx}{\linewidth}{@{}p{2.5cm}XcXc@{}}
        \toprule
        Variable   &  \multicolumn{3}{c}{Factor} \\
        \cmidrule(r){1-1} \cmidrule(l){2-4}    
        & \multicolumn{1}{c}{CCP} & \multicolumn{1}{c}{No.CCP} & \multicolumn{1}{c}{diff} \\
        \cmidrule(l){2-2}\cmidrule(l){3-3}\cmidrule(l){4-4}
        
        Gender   & mean(sd) & mean(sd) &  mean(sd)\\
        Married  & mean(sd) & mean(sd) &  mean(sd)\\
        Employed & mean(sd) & mean(sd) &  mean(sd) \\
        Education & mean(sd) & mean(sd) &  mean(sd) \\
        Party & mean(sd) & mean(sd) &  mean(sd) \\
        HR    & mean(sd) & mean(sd) &  mean(sd) \\
        Fin.Knowledge & mean(sd) & mean(sd) &  mean(sd) \\
        Fin.Inter & mean(sd) & mean(sd) &  mean(sd) \\
        
        Region- East   & mean(sd) & mean(sd) &  mean(sd) \\
        Region-Center  & mean(sd) & mean(sd) &  mean(sd) \\
        Region-West    & mean(sd) & mean(sd) &  mean(sd) \\
        
        
        Access Loan & mean(sd) & mean(sd) &  mean(sd)\\
        Formal & mean(sd) & mean(sd) & mean(sd) \\
        Informal & mean(sd) & mean(sd) &  mean(sd) \\
        Both & mean(sd) & mean(sd) &  mean(sd) \\
        No Loans & mean(sd) & mean(sd) &  mean(sd) \\
    
    \end{tabularx}
    
    
    \vspace{1ex}
    \footnotesize
    \begin{tabularx}{\linewidth}{@{}p{\dimexpr 2.5cm+\tabcolsep}@{\extracolsep{\fill}}*{3}{c}@{}}
        & \multicolumn{3}{c}{Continuous}\\
        \cmidrule{2-4}
        & CCP & No.CCP & t-test \\
        \cmidrule{2-4}
        Age    &     mean(sd)  & mean(sd)&   mean(sd)  \\
        Income &     mean(sd)  & mean(sd)&   mean(sd)  \\
        Networth &   mean(sd)  & mean(sd)&   mean(sd)  \\
        NW-HE &      mean(sd)  & mean(sd)&   mean(sd)  \\
        Liquid Assets & mean(sd)  & mean(sd)&   mean(sd)  \\
        \bottomrule
        \addlinespace
        \multicolumn{4}{@{}p{\textwidth}@{}}{\footnotesize Note: HR stands for Household Registration. NW-HE is net-worth minus home equity. All the asset variables (e.g. income, net-worth, NW-HE, and liquid assets are in Chinese renminbi (CNY).} \\
    \end{tabularx}
    \caption{Summary statistics}
    \label{tab:pol.dispersion}
\end{table}

\end{document}

enter image description here]1]1

1
  • 2
    what do you mean by align here, what do you want to align with what? I wouldn't use tabularx I would just use a normal tabular theer is no line breaking in the cells and no advantage in spreading the table to full width Jun 27, 2021 at 17:56

1 Answer 1

2

I would use a single tabular environment -- not tabularx, and not tabular*. To make sure the legend occupies the width of the tabular stuff (and no more), encase all contents of the table environment -- including the \caption and \label directives -- in a threeparttable environment.

enter image description here

\documentclass[11pt]{report}
% note: I've slimmed down the preamble to the bare minimum
\usepackage{booktabs,threeparttable,geometry}

\begin{document}    
\begin{table}
    \centering
    \begin{threeparttable}
    \begin{tabular}{@{} l ccc @{}}
    \toprule
        Variable   
        & \multicolumn{3}{c@{}}{Factor} \\
        \cmidrule(l){2-4}    
        & CCP & No CCP & diff \\ \addlinespace
        
        Gender    & mean(sd) & mean(sd) &  mean(sd) \\
        Married   & mean(sd) & mean(sd) &  mean(sd) \\
        Employed  & mean(sd) & mean(sd) &  mean(sd) \\
        Education & mean(sd) & mean(sd) &  mean(sd) \\
        Party     & mean(sd) & mean(sd) &  mean(sd) \\
        HR        & mean(sd) & mean(sd) &  mean(sd) \\
        Fin.\ Knowledge & mean(sd) & mean(sd) &  mean(sd) \\
        Fin.\ Interm.   & mean(sd) & mean(sd) &  mean(sd) \\
        
        Region--East   & mean(sd) & mean(sd) &  mean(sd) \\
        Region--Center & mean(sd) & mean(sd) &  mean(sd) \\
        Region--West   & mean(sd) & mean(sd) &  mean(sd) \\
        
        Access Loan & mean(sd) & mean(sd) &  mean(sd) \\
        Formal      & mean(sd) & mean(sd) &  mean(sd) \\
        Informal    & mean(sd) & mean(sd) &  mean(sd) \\
        Both        & mean(sd) & mean(sd) &  mean(sd) \\
        No Loans    & mean(sd) & mean(sd) &  mean(sd) \\[4mm]
        
        & \multicolumn{3}{c@{}}{Continuous}\\
        \cmidrule(l){2-4}
        & CCP & No CCP & $t$-test \\ \addlinespace
        
        Age           &   mean(sd)  & mean(sd)&   mean(sd)  \\
        Income        &   mean(sd)  & mean(sd)&   mean(sd)  \\
        Networth      &   mean(sd)  & mean(sd)&   mean(sd)  \\
        NW$-$HE       &   mean(sd)  & mean(sd)&   mean(sd)  \\
        Liquid Assets &   mean(sd)  & mean(sd)&   mean(sd)  \\
        \bottomrule
    \end{tabular}
    
    \medskip\footnotesize  % the legend for both parts of the table
    Note: HR stands for Household Registration. NW$-$HE is net worth 
    minus home equity. All the asset variables (e.g., income, 
    net worth, NW$-$HE, and liquid assets) are in Chinese 
    renminbi (CNY).
    
    \caption{Summary statistics}
    \label{tab:pol.dispersion}
    \end{threeparttable}
\end{table}

\end{document}

You must log in to answer this question.

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