在多列中添加一行

在多列中添加一行

我有一张如下所示的表格,我想正确添加一行收入 2在此处输入图片描述如照片所示,提前致谢。代码取自这里

    \documentclass[11pt,authoryear,sort&compress]{report}
\usepackage{booktabs,tabulary,array,tabularx}
\usepackage{geometry}
\newcolumntype{z}{>{\arraybackslash\centering}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}{\dimexpr\linewidth-2cm-4\tabcolsep}{zzz}  
                    West & East & Center \tabularnewline
                    \cmidrule(r){1-1}\cmidrule(rl){2-2}\cmidrule(l){3-3} 
                    27.7 \%  & 41.1 \%  & 30.2 \% \tabularnewline\end{tabularx}}
            \\\addlinespace[1em]

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

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

答案1

你(们)能做到表。

\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{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+2\tabcolsep][l]{Region}%
\begin{tabularx}{\dimexpr\linewidth-2cm-2\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 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}

在此处输入图片描述

答案2

您可能对以下输出感兴趣:

在此处输入图片描述

    \documentclass[11pt,authoryear,sort&compress]{report}
\usepackage{booktabs,tabulary,array,tabularx}
\usepackage{geometry}
\newcolumntype{z}{>{\arraybackslash\centering}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}{\dimexpr\linewidth-2cm-4\tabcolsep}{zzz}  
                    West & East & Center \tabularnewline
                    \cmidrule(r){1-1}\cmidrule(rl){2-2}\cmidrule(l){3-3} 
                    27.7 \%  & 41.1 \%  & 30.2 \% \tabularnewline\end{tabularx}}
            \\\addlinespace[1em]

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

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

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

相关内容