如何修复表格边距

如何修复表格边距

请求帮助... 大家好,我有两个问题,请你们帮忙解决。

(1) 有谁能告诉我如何让这个表格位于文档的边缘内?目前,第二列的标题似乎太宽了。如果您能建议一种方法,让我可以将第二列的标题缩小到两行,那么它可能会起作用。请参阅附图 1。我使用了以下代码(请参阅下面的代码):

图像 (1) - 第二列太宽

\begin{table}[H]
   \caption{Summary of gene inputs and pathway outputs for pathway analysis of the isografts}
   \small
   \centering
    \begin{tabular}{lllp{\dimexpr 0.65\linewidth-8\tabcolsep}}
   \toprule[\heavyrulewidth]\toprule[\heavyrulewidth]
   \textbf{Timepoint comparison} & \textbf{Total number of input genes (P < 0.01)} & \textbf{Pathway outputs} & \textbf{Number of statistically significant enriched pathways (P < 0.05)}\\ 
   \midrule
T0-T1g downregulated & 2308 & Immunological & 0\\
& & Inflammatory & 2 \\
T0-T1g upregulated & 2187 & Immunological & 14 \\
& & Inflammatory & 28 \\
T1g-T7g downregulated & 2034 & Immunological & 1\\
& & Inflammatory & 15 \\
T1g-T7g upregulated & 1897 & Immunological & 1\\
& & Inflammatory & 2 \\
T7g-T30g downregulated & 1360 & Immunological & 3\\
& & Inflammatory & 2 \\
T7g-T30g upregulated & 751 & Immunological & 4\\
& & Inflammatory & 8 \\\hdashline
   \bottomrule[\heavyrulewidth] 
   \end{tabular}
\end{table}

(2) 与上一个表格类似的问题,只是这一次,第二列的标题分为两行,但与列的其余部分不对齐。有人能告诉我一种将标题与列中的其余内容对齐的方法吗?请参阅附图 2。我使用了以下代码(请参阅下面的代码):

图像 (2) - 第二列标题和内容未对齐

\begin{table}[H]
\setlength{\tabcolsep}{2.5pt}
   \caption{Serum markers in the allograft recipients with no significant difference in concentrations between timepoints}
   \small
    \centering
   \begin{tabular}{ l p{\dimexpr 0.65\linewidth-2\tabcolsep}}
   \toprule[\heavyrulewidth]\toprule[\heavyrulewidth]
   \textbf{Serum marker} & \textbf{\makecell {Limit of Detection (LOD)\\(pg/mL)}}\\ 
   \midrule
1.  AR (amphiregulin) & 13.6\\ 
2.  B7-1 (CD80) & 35.3\\ 
3.  BAFF-R (B cell activating factor receptor)  & 7.7\\ 
4.  BTC (betacellulin)  & 5.7\\ 
5.  C5a (complement C5 alpha chain) & 1.7\\ 
6.  CCL6    (C-C motif chemokine 6) & 23.2\\ 
7.  CD6 (T cell differentiation antigen 6)  & 2.5\\ 
8.  CX3CL1 (Fractalkine)    & 2016.3\\ 
32. Marapsin & 77.7\\\hdashline
   \bottomrule[\heavyrulewidth] 
   \end{tabular}
\end{table}

请参阅以下有关我在代码中使用的一些参数的详细信息,因为它可能会有所帮助;

\documentclass[12pt, a4paper]{report}
\input{Packages.tex} included the following;

    % For tables
    \usepackage{threeparttable}
    \usepackage{threeparttablex}
    \usepackage{ctable}
    \usepackage{tabularx}
    \usepackage{rotating}
    \usepackage{makecell}
    \usepackage{longtable}
    
    % other
    \usepackage[T1]{fontenc}
    \usepackage[latin1]{inputenc}
    \usepackage[english]{babel}
    \usepackage{siunitx}
    \usepackage{graphicx}
    \usepackage{tipa} % for the \ark{} command
    \usepackage{graphics} % for pdf, bitmapped graphics files
    \usepackage{times} % assumes new font selection scheme installed
    \usepackage{amsmath}
    \usepackage{latexsym}
    \usepackage{amscd}% for commutative diagrams
    \usepackage{mathrsfs} %this package is for the script font \mathscr
    \usepackage{relsize}
    \usepackage{delarray}
    \usepackage{pstricks}
    \usepackage{theorem}
    \usepackage{changepage}
    \usepackage{euscript}
    \usepackage{textcomp}
    \usepackage{esvect}
    \usepackage{parskip}
    \usepackage{placeins}
    \usepackage{subfigure}

答案1

编辑:* 现在两个表:

在此处输入图片描述

在此处输入图片描述

使用tabularray带有库的包booktabssiunitx

\documentclass[12pt, a4paper]{report}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage{newtxtext} 
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
  \ExplSyntaxOn
\NewChildSelector{eachtwo}
  {
    \int_step_inline:nnnn {2}{2}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff

\begin{document}
\begin{table}[ht]
   \caption{Summary of gene inputs and pathway outputs for pathway analysis of the isografts}
\begin{tblr}{colsep  = 3pt,
             colspec = {@{} l
                        X[0.8, c, si={table-format=4.0}] 
                        l
                        X[1.2, c, si={table-format=2.0}]
                        @{}},
            rowsep = 0.5pt,
            row{1} = {font=\small\bfseries, m},
            row{eachtwo} = {abovesep=1ex},
            }
   \toprule
{Timepoint\\ comparison}
    & {{{Total number\\ of input genes $(P<0.01)$}}} 
        & {{{Pathway\\ outputs}}} 
            & {{{No. of statistically significant enriched pathways $(P<0.05)$}}}\\
   \midrule
T0-T1g downregulated 
    & 2308  & Immunological & 0             \\
    &       & Inflammatory  & 2             \\
T0-T1g upregulated 
    & 2187  & Immunological & 14            \\
    &       & Inflammatory  & 28            \\
T1g-T7g downregulated 
    & 2034  & Immunological & 1             \\
    &       & Inflammatory  & 15            \\
T1g-T7g upregulated 
    & 1897  & Immunological & 1             \\
    &       & Inflammatory  & 2             \\
T7g-T30g downregulated 
    & 1360  & Immunological & 3             \\
    &       & Inflammatory  & 2             \\
T7g-T30g upregulated 
    & 751   & Immunological & 4             \\
    &       & Inflammatory  & 8             \\
   \bottomrule
   \end{tblr}
\end{table}


\begin{table}[ht]
   \caption{Serum markers in the allograft recipients with no significant difference in concentrations between timepoints}
\begin{tblr}{colspec = {c
                        X[l]
                        Q[c, si={table-format=4.1}]
                        },
            rowsep = 0.5pt,
            row{1} = {font=\small\bfseries, c, m},
            row{eachtwo} = {abovesep=1ex},
            }
   \toprule
{Serum\\ marker}
    & \SetCell[c=2]{c}  {Limit of Detection (LOD)\\ (pg/mL)}
                            &           \\
   \midrule
1.  &   AR (amphiregulin)   & 13.6      \\
2.  &   B7-1 (CD80)         & 35.3      \\
3.  &   BAFF-R (B cell activating factor receptor)
                            & 7.7       \\
4.  &   BTC (betacellulin)  & 5.7       \\
5.  &   C5a (complement C5 alpha chain)
                            & 1.7       \\
6.  &   CCL6    (C-C motif chemokine 6)
                            & 23.2      \\
7.  &   CD6 (T cell differentiation antigen 6)
                            & 2.5       \\
8.  &   CX3CL1 (Fractalkine)& 2016.3    \\
32. &   Marapsin            & 77.7      \\
   \bottomrule
   \end{tblr}
\end{table}
\end{document}

答案2

在第一个表中,您需要允许第 2 至第 4 列自动换行。对于这两个表,我建议您使用tabularx而不是tabular环境。我认为没有必要粗体标题单元格的内容。我会将数字数据与它们的显式或隐式小数点对齐。表 2 中的自动行编号可能也是可取的。

在此处输入图片描述

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabularx} % for 'tabularx' env. and 'X' col. type
\usepackage{ragged2e} % for '\RaggedRight' and '\Centering' environment
\newcolumntype{L}{>{\RaggedRight}X} % raggedright version of 'X' col. type
\newcolumntype{C}{>{\Centering}X}   % centered version of 'X' col. type

\newcommand\mC[1]{\multicolumn{1}{C@{}}{#1}} % handy shortcut macro

\usepackage[per-mode=symbol]{siunitx}% for 'S' col. type and '\unit' macro

%% enable automatic row numbering in tables:
\newcounter{tblrow}[table]
\newcolumntype{t}{>{\refstepcounter{tblrow}\thetblrow.}r}
\begin{document}

\begin{table}[ht]
\setlength\tabcolsep{3pt} % default: 6pt
\caption{Summary of gene inputs and pathway outputs 
 for pathway analysis of the isografts}
\begin{tabularx}{\textwidth}{@{} l S[table-format=4.0] C S[table-format=4.1] @{}}
\toprule
Timepoint comparison & 
\mC{Total number of input genes ($P < 0.01$)} & 
Pathway outputs & 
\mC{Number of stat.\ sign.\ enriched pathways ($P < 0.05$)} \\ 
\midrule
T0-T1g downregulated & 2308 & Immunological & 0\\
& & Inflammatory & 2 \\
T0-T1g upregulated & 2187 & Immunological & 14 \\
& & Inflammatory & 28 \\
\addlinespace
T1g-T7g downregulated & 2034 & Immunological & 1\\
& & Inflammatory & 15 \\
T1g-T7g upregulated & 1897 & Immunological & 1\\
& & Inflammatory & 2 \\
\addlinespace
T7g-T30g downregulated & 1360 & Immunological & 3\\
& & Inflammatory & 2 \\
T7g-T30g upregulated & 751 & Immunological & 4\\
& & Inflammatory & 8 \\   %%\hdashline
\bottomrule[\heavyrulewidth] 
\end{tabularx}

\bigskip\bigskip
\caption{Serum markers in the allograft recipients with no 
  significant difference in concentrations between timepoints}
\begin{tabularx}{\textwidth}{@{} t L S[table-format=4.1] @{}}
\toprule
% '\multicolumn{1}{@{}l}{}' serves to suppress display of row counter
\multicolumn{1}{@{}l}{} & Serum marker & {Limit of Detection (LOD)} \\
\multicolumn{1}{@{}l}{} && {(\unit{\pico\gram\per\milli\liter}) } \\ 
\midrule
& AR (amphiregulin) & 13.6\\ 
& B7-1 (CD80) & 35.3\\ 
& BAFF-R (B cell activating factor receptor)  & 7.7\\ 
& BTC (betacellulin)  & 5.7\\ 
& C5a (complement C5 alpha chain) & 1.7\\ 
& CCL6    (C-C motif chemokine 6) & 23.2\\ 
& CD6 (T cell differentiation antigen 6)  & 2.5\\ 
& CX3CL1 (Fractalkine)    & 2016.3\\  
\multicolumn{1}{@{}r}{\setcounter{tblrow}{31}}& \dots \\
& Marapsin & 77.7\\ % reset value of 'tblrow' counter
\bottomrule 
\end{tabularx}
\end{table}

\end{document}

相关内容