表格内的子组

表格内的子组

我正在尝试创建下表,以便用红色标记的部分作为缩进的子组列出,而其他部分则不缩进。

在此处输入图片描述

我尝试过多列。但是,它只起到了部分作用。

这是当前表的乳胶代码:“”

\begin{table*}[hbt]
\centering
\caption{Recipient, Donor, and Kidney Transplant Characteristics of the Study Population (n=27814) and the corresponding p-values from the Univariate Cox Regression Proportional Hazards Model}
\label{tab:Characteristics }
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lcc@{}}
\toprule
\textbf{Covariate}                        & \textbf{Mean+SD/ n (\%)} & \textbf{P Value} \\ \midrule
Recipient’s age (years)                   & 47.09$\pm$12.44              & \textless{}0.005 \\
Recipient’s BMI (kg/m2)                   & 26.79$\pm$5.35               & \textless{}0.005 \\
Recipient’s blood type                    &                           & 0.01             \\
O                                         & 12616 (45.36\%)           &                  \\
A                                         & 10049 (36.13\%)           &                  \\
B                                         & 3499 (12.58\%)            &                  \\
AB                                        & 1206 (4.34\%)             &                  \\
A1                                        & 346 (1.24\%)              &                  \\
A2                                        & 60 (0.22\%)               &                  \\
A1B                                       & 30 (0.11\%)               &                  \\
A2B                                       & 7 (0.03\%)                &                  \\
Unknown                                   & 1 (0.00\%)                &                  \\
Recipient’s sex                           &                           & 0.06             \\
Male                                      & 16398 (58.96\%)           &                  \\
Female                                    & 11416 (41.04\%)           &                  \\
Recipient's ethnicity                     &                           & 0.24             \\
White                                     & 16331 (58.72\%)           &                  \\
Black or African American                 & 5721 (20.57\%)            &                  \\
Hispanic/Latino                           & 3731 (13.41\%)            &                  \\
Asian                                     & 1599 (5.75\%)             &                  \\
American Indian or Alaska Native          & 252 (0.91\%)              &                  \\
Native Hawaiian or Other Pacific Islander & 116 (0.42\%)              &                  \\
Other                                     & 64 (0.24\%)               &                  \\
Donor's age (years)                       & 39.38$\pm$12.40              & \textless{}0.005 \\
Donor’s blood type                        &                           & 0.14             \\
O                                         & 15258 (54.86\%)           &                  \\
A                                         & 5445 (19.58\%)            &                  \\
B                                         & 3283 (11.80\%)            &                  \\
AB                                        & 2767 (9.95\%)             &                  \\
A1                                        & 494 (1.78\%)              &                  \\
A2                                        & 403 (1.45\%)              &                  \\
A1B                                       & 132 (0.47\%)              &                  \\
A2B                                       & 30 (0.11\%)               &                  \\
Unknown                                   & 2 (0.01\%)                &                  \\
Donor's sex                               &                           & 0.36             \\
Male                                      & 14863 (53.44\%)           &                  \\
Female                                    & 12951 (46.56\%)           &                  \\
Donor recipient-gender match              &                           & 0.45             \\
Yes                                       & 14067 (50.58\%)           &                  \\
No                                        & 13747 (49.42\%)           &                  \\
Num of A mismatches at transplant         & 1.09 $\pm$ 0.76              & \textless{}0.005 \\
Num of B mismatches at transplant         & 1.21 $\pm$ 0.76              & \textless{}0.005 \\
Num of DR mismatches at transplant        & 0.94 $\pm$ 0.73              & \textless{}0.005 \\
Num of HLA mismatches at transplant                       & 3.24 $\pm$ 1.83   & \textless{}0.005 \\
Total Cold Ischemic Time (hours)          & 12.09 $\pm$ 11.09            & \textless{}0.005 \\
Duration of hospitalization after transplant (days)       & 5.91$\pm$2.22     & \textless{}0.005 \\
Elapsed time between first dialysis and transplant (days) & 841.08$\pm$670.09 & \textless{}0.005 \\
Serum Creatinine at Discharge             & 2.55$\pm$2.31                & \textless{}0.005 \\
Serum creatinine at 6 months              & 1.41$\pm$0.51                & \textless{}0.005 \\
Serum creatinine at 1 year                & 1.40$\pm$0.47                & \textless{}0.005 \\ \bottomrule
\end{tabular*}%
\end{table*}

'''

答案1

为了最大限度地减少打字,定义了两种环境:非缩进条目(NoIndent)和缩进条目(Indent)。

第二个是可选参数,用于输入所需的缩进(默认 =0pt)。

b

\documentclass[11pt,a4paper]{article}
\usepackage{booktabs}
\usepackage[left=1.00cm, right=3.00cm, top=1.00cm, bottom=1.00cm, showframe]{geometry} % fit the table into a page


%*************************************** added <<<<<<<<<<<<<<
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\arraybackslash}p{#1}}

\usepackage{environ}% define enviroments

\NewEnviron{NoIndent}{% no indent
    \setlength{\tabcolsep}{0pt}
    \setlength\arrayrulewidth{0pt}
\begin{tabular*}{\textwidth}{@{}R{0.4\linewidth}C{0.4\linewidth}C{0.3\linewidth}@{}}
        \BODY
    \end{tabular*}%
}

\NewEnviron{Indented}[1][0pt]{% indented, default =0 pt
    \setlength{\tabcolsep}{0pt}
    \setlength\arrayrulewidth{0pt}
    \begin{tabular*}{\textwidth}{@{\hspace{#1}}R{\dimexpr0.4\linewidth-#1}C{0.4\linewidth}C{0.3\linewidth}@{}}
        \BODY
    \end{tabular*}%
}
%***************************************


\begin{document}
\begin{table*}[hbt]
    \centering
    \caption{Recipient, Donor, and Kidney Transplant Characteristics of the Study Population (n=27814) and the corresponding p-values from the Univariate Cox Regression Proportional Hazards Model}
    \label{tab:Characteristics }
    \begin{NoIndent}
        \toprule
        \textbf{Covariate}                        & \textbf{Mean+SD/ n (\%)} & \textbf{P Value} \\ \midrule
        Recipient’s age (years)                   & 47.09$\pm$12.44              & \textless{}0.005 \\
        Recipient’s BMI (kg/m2)                   & 26.79$\pm$5.35               & \textless{}0.005 \\[0.3ex]
        Recipient’s blood type                    &                           & 0.01             \\
    \end{NoIndent}%

    \begin{Indented}[20pt]
        O                                         & 12616 (45.36\%)           &                  \\
        A                                         & 10049 (36.13\%)           &                  \\
        B                                         & 3499 (12.58\%)            &                  \\
        AB                                        & 1206 (4.34\%)             &                  \\
        A1                                        & 346 (1.24\%)              &                  \\
        A2                                        & 60 (0.22\%)               &                  \\
        A1B                                       & 30 (0.11\%)               &                  \\
        A2B                                       & 7 (0.03\%)                &                  \\
        Unknown                                   & 1 (0.00\%)                &                  \\
    \end{Indented}% 
        
        \begin{NoIndent}
        Recipient’s sex                           &                           & 0.06            
        \end{NoIndent}%

        \begin{Indented}[20pt]
        Male                                      & 16398 (58.96\%)           &                  \\
        Female                                    & 11416 (41.04\%)           &                  \\
        \end{Indented}% 
    
        \begin{NoIndent}
        Recipient's ethnicity                   &                           & 0.24             \\
        \end{NoIndent}%
                
        \begin{Indented}[20pt]
        White                                     & 16331 (58.72\%)           &                  \\
        Black or African American                 & 5721 (20.57\%)            &                  \\
        Hispanic/Latino                           & 3731 (13.41\%)            &                  \\
        Asian                                     & 1599 (5.75\%)             &                  \\
        American Indian or Alaska Native          & 252 (0.91\%)              &                  \\
        Native Hawaiian or Other Pacific Islander & 116 (0.42\%)              &                  \\
        Other                                     & 64 (0.24\%)               &                  \\
        \end{Indented}% %
        
        \begin{NoIndent}
        Donor's age (years)                       & 39.38$\pm$12.40              & \textless{}0.005 \\
        Donor’s blood type                        &                           & 0.14             \\
        \end{NoIndent}% 
    
    \begin{Indented}[20pt]
        O                                         & 15258 (54.86\%)           &                  \\
        A                                         & 5445 (19.58\%)            &                  \\
        B                                         & 3283 (11.80\%)            &                  \\
        AB                                        & 2767 (9.95\%)             &                  \\
        A1                                        & 494 (1.78\%)              &                  \\
        A2                                        & 403 (1.45\%)              &                  \\
        A1B                                       & 132 (0.47\%)              &                  \\
        A2B                                       & 30 (0.11\%)               &                  \\
        Unknown                                   & 2 (0.01\%)                &                  \\
    \end{Indented}% %

    \begin{NoIndent}
        Donor's sex                               &                           & 0.36             \\
    \end{NoIndent}
            
    \begin{Indented}[20pt]
        Male                                      & 14863 (53.44\%)           &                  \\
        Female                                    & 12951 (46.56\%)           &                  \\
    \end{Indented}% %

    \begin{NoIndent}
            Donor recipient-gender match          &                           & 0.45             \\
    \end{NoIndent}% 
    
    \begin{Indented}[20pt]
        Yes                                       & 14067 (50.58\%)           &                  \\
        No                                        & 13747 (49.42\%)           &                  \\
    \end{Indented}% %

    \begin{NoIndent}
        Num of A mismatches at transplant         & 1.09 $\pm$ 0.76              & \textless{}0.005 \\
        Num of B mismatches at transplant         & 1.21 $\pm$ 0.76              & \textless{}0.005 \\
        Num of DR mismatches at transplant        & 0.94 $\pm$ 0.73              & \textless{}0.005 \\
        Num of HLA mismatches at transplant                       & 3.24 $\pm$ 1.83   & \textless{}0.005 \\
        Total Cold Ischemic Time (hours)          & 12.09 $\pm$ 11.09            & \textless{}0.005 \\
        Duration of hospitalization after transplant (days)       & 5.91$\pm$2.22     & \textless{}0.005 \\
        Elapsed time between first dialysis and transplant (days) & 841.08$\pm$670.09 & \textless{}0.005 \\
        Serum Creatinine at Discharge             & 2.55$\pm$2.31                & \textless{}0.005 \\
        Serum creatinine at 6 months              & 1.41$\pm$0.51                & \textless{}0.005 \\
        Serum creatinine at 1 year                & 1.40$\pm$0.47                & \textless{}0.005 \\ \bottomrule
    \end{NoIndent}% 

\end{table*}
\end{document}

答案2

您可以添加一个具有缩进长度的额外列并合并任意两个不应显示缩进的单元格。

此外,表格很长,可能跨越多个页面。这可以由一些环境支持(例如longtablexltabular)。下面的解决方案基于xltabular,它还添加了X列类型,这很方便,因为它会自动计算所有列类型设置为的列的剩余宽度X

在此处输入图片描述

\documentclass[11pt,a4paper]{article}
\usepackage{geometry}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup[table]{skip=6pt}
\usepackage{xltabular}

\setlength{\tabcolsep}{0pt}

\newcommand\mcc[1]{\multicolumn{2}{@{}l}{#1}}


\begin{document}
\begin{xltabular}{\textwidth}{p{15pt} @{\extracolsep{\fill}} X r @{\hspace{0.5em}} r}
  %%% The first head
  \caption{Recipient, Donor, and Kidney Transplant Characteristics of the Study Population (n=27814) and the corresponding p-values from the Univariate Cox Regression Proportional Hazards Model}\label{tab:Characteristics} \\
  \toprule
  \mcc{\textbf{Covariate}}
  & \textbf{Mean+SD/ n (\%)} & \textbf{P Value} \\
  \midrule \endfirsthead
  %%% Subsequent heads
  \caption{Recipient, Donor ... (Continued)} \\
  \toprule
  \mcc{\textbf{Covariate}} & \textbf{Mean+SD/ n (\%)} & \textbf{P Value} \\
  \midrule \endhead

  %%% Subsequent foot
  \bottomrule \\[-0.75\normalbaselineskip]
  \multicolumn{4}{r@{}}{\itshape Continues on the next page ...}\endfoot
  %%% The last foot
  \bottomrule \endlastfoot

  \mcc{Recipient’s age (years)}              & 47.09$\pm$12.44          & \textless{}0.005 \\
  \mcc{Recipient’s BMI (kg/m2)}              & 26.79$\pm$5.35           & \textless{}0.005 \\
  \mcc{Recipient’s blood type}               &                          & 0.01             \\
  & O                                                         & 12616 (45.36\%)          &                  \\
  & A                                                         & 10049 (36.13\%)          &                  \\
  & B                                                         & 3499 (12.58\%)           &                  \\
  & AB                                                        & 1206 (4.34\%)            &                  \\
  & A1                                                        & 346 (1.24\%)             &                  \\
  & A2                                                        & 60 (0.22\%)              &                  \\
  & A1B                                                       & 30 (0.11\%)              &                  \\
  & A2B                                                       & 7 (0.03\%)               &                  \\
  & Unknown                                                   & 1 (0.00\%)               &                  \\
  \mcc{Recipient’s sex}                      &                          & 0.06             \\
  & Male                                                      & 16398 (58.96\%)          &                  \\
  & Female                                                    & 11416 (41.04\%)          &                  \\
  & Recipient's ethnicity                                     &                          & 0.24             \\
  & White                                                     & 16331 (58.72\%)          &                  \\
  & Black or African American                                 & 5721 (20.57\%)           &                  \\
  & Hispanic/Latino                                           & 3731 (13.41\%)           &                  \\
  & Asian                                                     & 1599 (5.75\%)            &                  \\
  & American Indian or Alaska Native                          & 252 (0.91\%)             &                  \\
  & Native Hawaiian or Other Pacific Islander                 & 116 (0.42\%)             &                  \\
  & Other                                                     & 64 (0.24\%)              &                  \\
  \mcc{Donor's age (years)}                  & 39.38$\pm$12.40          & \textless{}0.005 \\
  \mcc{Donor’s blood type}                   &                          & 0.14             \\
  & O                                                         & 15258 (54.86\%)          &                  \\
  & A                                                         & 5445 (19.58\%)           &                  \\
  & B                                                         & 3283 (11.80\%)           &                  \\
  & AB                                                        & 2767 (9.95\%)            &                  \\
  & A1                                                        & 494 (1.78\%)             &                  \\
  & A2                                                        & 403 (1.45\%)             &                  \\
  & A1B                                                       & 132 (0.47\%)             &                  \\
  & A2B                                                       & 30 (0.11\%)              &                  \\
  & Unknown                                                   & 2 (0.01\%)               &                  \\
  \mcc{Donor's sex}                          &                          & 0.36             \\
  & Male                                                      & 14863 (53.44\%)          &                  \\
  & Female                                                    & 12951 (46.56\%)          &                  \\
  & Donor recipient-gender match                              &                          & 0.45             \\
  & Yes                                                       & 14067 (50.58\%)          &                  \\
  & No                                                        & 13747 (49.42\%)          &                  \\
  \mcc{Num of A mismatches at transplant}    & 1.09 $\pm$ 0.76          & \textless{}0.005 \\
  \mcc{Num of B mismatches at transplant}    & 1.21 $\pm$ 0.76          & \textless{}0.005 \\
  \mcc{Num of DR mismatches at transplant}   & 0.94 $\pm$ 0.73          & \textless{}0.005 \\
  \mcc{Num of HLA mismatches at transplant}  & 3.24 $\pm$ 1.83          & \textless{}0.005 \\
  \mcc{Total Cold Ischemic Time (hours)}     & 12.09 $\pm$ 11.09        & \textless{}0.005 \\
  \mcc{Duration of hospitalization after transplant (days)} & 5.91$\pm$2.22 & \textless{}0.005 \\
  \mcc{Elapsed time between first dialysis and transplant (days)} & 841.08$\pm$670.09 & \textless{}0.005 \\
  \mcc{Serum Creatinine at Discharge}        & 2.55$\pm$2.31            & \textless{}0.005 \\
  \mcc{Serum creatinine at 6 months}         & 1.41$\pm$0.51            & \textless{}0.005 \\
  \mcc{Serum creatinine at 1 year}           & 1.40$\pm$0.47            & \textless{}0.005 \\
\end{xltabular}
\end{document}

答案3

类似于@Celdor 的答案,但是

  • tabularray` 包的使用
  • 插入另一列用于分隔Mean + SD/n (\%)数据
\documentclass[11pt]{article}
\usepackage[a4paper]{geometry}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{caption}
  \captionsetup[table]{skip=0.33\baselineskip}

\begin{document}

\begingroup2
\NewTableCommand\SCtwo{\SetCell{wd=\dimexpr0.4\linewidth+1em+3\tabcolsep, 
                                cmd=\Ident}}
\newcommand*{\Ident}{%
  \raggedright
  \hangafter=1              % <---
  \hangindent=1ex\relax     % <---
                            }

\begin{longtblr}[
caption={Recipient, Donor, and Kidney Transplant Characteristics of the Study Population ($n=27814$) and the corresponding p-values from the Univariate Cox Regression Proportional Hazards Model},
  label={tab:Characteristics}
                ]{colspec = {@{}Q[l, wd=1em] 
                                Q[l, wd=0.4\linewidth]
                                X[r] 
                                X[l]    r},
                 rowsep  = {0pt},
                 row{1}  = {font=\bfseries, mode=text},
                 rowhead=1
                 }
    \toprule
  & Covariate                           & \SetCell[c=2]{c}  Mean + SD/n (\%)
                                                    &               &  P Value      \\
    \midrule
\SCtwo  Recipient’s age (years)         && \SetCell[c=2]{c,$} 47.09 \pm 12.44
                                                    &               &  \textless{}0.005     \\
\SCtwo  Recipient’s BMI (kg/m2)         && \SetCell[c=2]{c,$} 26.79 \pm 5.35   
                                                    &               &  \textless{}0.005     \\
\SCtwo  Recipient’s blood type          &&          &               &   0.01        \\
  & O                                   & 12616     &  (45.36\%)    &               \\
  & A                                   & 10049     &  (36.13\%)    &               \\
  & B                                   & 3499      &  (12.58\%)    &               \\
  & AB                                  & 1206      &  (4.34\%)     &               \\
  & A1                                  & 346       &  (1.24\%)     &               \\
  & A2                                  & 60        &  (0.22\%)     &               \\
  & A1B                                 & 30        &  (0.11\%)     &               \\
  & A2B                                 & 7         &  (0.03\%)     &               \\
  & Unknown                             & 1         &  (0.00\%)     &               \\
\SCtwo      Recipient’s sex             &&                      &   & 0.06      \\
  & Male                                & 16398 &  (58.96\%)    &                  \\
  & Female                              & 11416 &  (41.04\%)    &                  \\
  & Recipient's ethnicity               &                       & 0.24             \\
  & White                               & 16331 &  (58.72\%)    &                  \\
  & Black or African American           & 5721  &  (20.57\%)    &                  \\
  & Hispanic/Latino                     & 3731  &  (13.41\%)    &                  \\
  & Asian                               & 1599  &  (5.75\%)     &                  \\
  & American Indian or Alaska Native    & 252   &  (0.91\%)     &                  \\
  & Native Hawaiian or Other Pacific Islander    
                                        & 116   &  (0.42\%)     &                  \\
  & Other                               & 64    &  (0.24\%)     &                  \\
\SCtwo  Donor's age (year)              &&  \SetCell[c=2]{c,$}  39.38 \pm 12.40
                                                &               & \textless{}0.005 \\
\SCtwo  Donor’s blood type              &&      &               & 0.14             \\
  & O                                   & 15258 &  (54.86\%)    &                  \\
  & A                                   & 5445  &  (19.58\%)    &                  \\
  & B                                   & 3283  &  (11.80\%)    &                  \\
  & AB                                  & 2767  &  (9.95\%)     &                  \\
  & A1                                  & 494   &  (1.78\%)     &                  \\
  & A2                                  & 403   &  (1.45\%)     &                  \\
  & A1B                                 & 132   &  (0.47\%)     &                  \\
  & A2B                                 & 30    &  (0.11\%)     &                  \\
  & Unknown                             & 2     &  (0.01\%)     &                  \\
\SCtwo  Donor's sex                     &       &               & 0.36             \\
  & Male                                & 14863 &  (53.44\%)    &                  \\
  & Female                              & 12951 &  (46.56\%)    &                  \\
  & Donor recipient-gender match        &                       & 0.45             \\
  & Yes                                 & 14067 &  (50.58\%)    &                  \\
  & No                                  & 13747 &  (49.42\%)    &                  \\
\SCtwo  Num of A mismatches at transplant   
                                        && \SetCell[c=2]{c,$} 1.09  \pm  0.76
                                                &               & \textless{}0.005 \\
\SCtwo  Num of B mismatches at transplant   
                                        && \SetCell[c=2]{c,$} 1.21  \pm  0.76
                                                &               & \textless{}0.005 \\
\SCtwo  Num of DR mismatches at transplant  
                                        && \SetCell[c=2]{c,$} 0.94  \pm  0.73
                                                &               & \textless{}0.005 \\
\SCtwo  Num of HLA mismatches at transplant 
                                        && \SetCell[c=2]{c,$} 3.24 \pm  1.83
                                                &               & \textless{}0.005 \\
\SCtwo  Total Cold Ischemic Time (hours)
                                        && \SetCell[c=2]{c,$} 12.09 \pm  11.09
                                                &               & \textless{}0.005 \\
\SCtwo  Duration of hospitalization after transplant (days)
                                        && \SetCell[c=2]{c,$}  5.91 \pm  2.22
                                                &               & \textless{}0.005 \\
\SCtwo  Elapsed time between first dialysis and transplant days)
                                        &&  \SetCell[c=2]{c,$} 841.08 \pm 670.09
                                                &               & \textless{}0.005 \\
\SCtwo  Serum Creatinine at Discharge   && \SetCell[c=2]{c,$}   2.55 \pm 2.31
                                                &               & \textless{}0.005 \\
\SCtwo  Serum creatinine at 6 months    && \SetCell[c=2]{c,$}  1.41 \pm 0.51
                                                &               & \textless{}0.005 \\
\SCtwo  Serum creatinine at 1 year      && \SetCell[c=2]{c,$}  1.40 \pm 0.47
                                                &               & \textless{}0.005 \\
    \bottomrule
\end{longtblr}
\end{document}

在此处输入图片描述

(红线表示页面布局)

相关内容