tabularx{} 中的对齐

tabularx{} 中的对齐

如果您能调整表格的话我将非常感激。提前谢谢您。

\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}

在此处输入图片描述]1]1

答案1

我会使用单个tabular环境——不是tabularx,也不是tabular*。为了确保图例占据tabular内容的宽度(并且不会更多),将table环境的所有内容(包括\caption\label指令)包裹在一个threeparttable环境中。

在此处输入图片描述

\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}

相关内容