多列对齐

多列对齐

获取代码这里这里但我无法将其正确放入页面在此处输入图片描述

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

答案1

我认为最好的选择是使用三个独立的tabular环境tabularx

我还会将数据列中的数字与各自的小数分隔符对齐。

在此处输入图片描述

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

相关内容