如何减少表格单元格{}{}的列宽?

如何减少表格单元格{}{}的列宽?

我使用以下方式生成了下表https://www.latex-tables.com/#distractor我需要将和之间的列间距handled减小到自定义值。主列之间仍需要留出一些间距,因此我不能简单地删除该列。在不更改代码的情况下,最简单的方法是什么?我试过了,cell{1}{5} = {c}{0.1cm}但最终还是发生了偏移handled

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subfig}
\usepackage{tabularray}

\begin{document}

\begin{table}
\centering
\resizebox{\linewidth}{!}{%
\begin{tblr}{
  cell{1}{2} = {c=3}{c},
  cell{1}{6} = {c=3}{c},
  cell{1}{10} = {c=3}{c},
  cell{1}{14} = {c=3}{c},
  cell{1}{18} = {c=3}{c},
  cell{2}{2} = {c},
  cell{2}{3} = {c},
  cell{2}{6} = {c},
  cell{2}{7} = {c},
  cell{2}{10} = {c},
  cell{2}{11} = {c},
  cell{2}{14} = {c},
  cell{2}{15} = {c},
  cell{2}{18} = {c},
  cell{2}{19} = {c},
  hline{1,9} = {-}{0.08em},
  hline{2} = {2-4,6-8,10-12,14-16,18-20}{},
  hline{3,6-7} = {-}{},
}
          & Distractor &     &      &  & Handled &     &      &  & Average &     &      &  & Accuracy &     &      &  & Human &     &      \\
method    & -1:0       & 0:2 & 0:2* &  & -1:0    & 0:2 & 0:2* &  & -1:0    & 0:2 & 0:2* &  & -1:0     & 0:2 & 0:2* &  & -1:0  & 0:2 & 0:2* \\
MOD       &            &     &      &  &         &     &      &  &         &     &      &  &          &     &      &  &       &     &      \\
MTGCN     &            &     &      &  &         &     &      &  &         &     &      &  &          &     &      &  &       &     &      \\
CAHMP     &            &     &      &  &         &     &      &  &         &     &      &  &          &     &      &  &       &     &      \\
Ours      &            &     &      &  &         &     &      &  &         &     &      &  &          &     &      &  &       &     &      \\
w/o clf   &            &     &      &  &         &     &      &  &         &     &      &  &          &     &      &  &       &     &      \\
w/ GT clf &            &     &      &  &         &     &      &  &         &     &      &  &          &     &      &  &       &     &      
\end{tblr}
}
\end{table}

\end{document}

编辑

\begin{table}[ht]
\footnotesize
\setlength\tabcolsep{-5pt} % let LaTeX figure out the best intercol. separation
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{15}{c} }
\toprule
& \multicolumn{3}{c}{Distractor} & \multicolumn{3}{c}{Handled} & \multicolumn{3}{c}{Average} & \multicolumn{3}{c}{Accuracy} & \multicolumn{3}{c}{Human}   \\
\cmidrule{2-4} \cmidrule{5-7} \cmidrule{8-10} \cmidrule{11-13} \cmidrule{14-16} 
Method & -1:0 & 0:2 & 0:2* & -1:0 & 0:2 & 0:2* & -1:0 & 0:2 & 0:2* & -1:0 & 0:2 & 0:2* & -1:0 & 0:2 & 0:2* \\
\midrule
MTGCN     & x & & & & & & & & & & & & & & x \\
CAHMP     & x & & & & & & & & & & & & & & x \\
MOD       & x & & & & & & & & & & & & & & x \\
\midrule
Ours      & x & & & & & & & & & & & & & & x \\
\midrule
w/o CLF   & x & & & & & & & & & & & & & & x \\
w/ GT CT  & 0.0 & 0.0 & 0.0 & 48.8 & 97.2 & 90.4 & 8.8 & 32.1 & 28.9 & 1.00 & 1.00 & 1.00 & 14.2 & 52.7 & 45.4 \\
\bottomrule
\end{tabular*}
\end{table}

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

    \begin{document}
    \begin{table}
    \centering
    \begin{tblr}{colsep  = {3pt},
                 colspec = {@{}  Q[l] 
                            *{5}{X[c, leftsep=15pt]X[c]X[c]}
                            @{}},
                 }
       \toprule
            &   Distractor 
                &   &   &   Handled 
                            &   &   &   Average 
                                        &   &   &   Accuracy 
                                                    &   &   &   Human
                                                                 &   &   \\
        \cmidrule[l=-0.8]{2-4}  \cmidrule[l=-0.8]{5-7} \cmidrule[l=-0.8]{8-10}
        \cmidrule[l=-0.8]{11-13}\cmidrule[l=-0.8]{14-16}
    method  & -1:0  & 0:2 & 0:2*    & -1:0  & 0:2   & 0:2*    & -1:0  & 0:2 & 0:2*    
            & -1:0  & 0:2 & 0:2*    & -1:0  & 0:2   & 0:2*  \\
        \midrule
    MOD     &       &     &         &       &       &           &   &   &   
            &       &     &         &       &       &       \\
    MTGCN   &       &     &         &       &       &           &   &   &
            &       &     &         &       &       &       \\
    CAHMP   &       &     &         &       &       &           &   &   &
            &       &     &         &       &       &       \\
    Ours    &       &     &         &       &       &           &   &   &
            &       &     &         &       &       &       \\
    w/o clf &       &     &         &       &       &           &   &   &
            &       &     &         &       &       &       \\
    w/ GT cl&       &     &         &       &       &           &   &   &
            &       &     &         &       &       &       \\
    \bottomrule
    \end{tblr}
    \end{table}
    \end{document}

在此处输入图片描述

答案1

您的表格有点太宽,无法很好地容纳文本块。可以通过以下方法解决:

  • 定义宽文本块,如下面的 MWE 中所示
  • 减小字体大小

**编辑(1):** 不幸的是,表格主体中单元格的内容是未知的,因此可能需要使用较小的字体大小或不同的列类型。

关于您的评论,现在在列组之间插入了更多空间。

\documentclass{article}
\usepackage{geometry}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    \begin{table}
    \centering
\begin{tblr}{colsep  = {3pt},
             colspec = {@{}  Q[l] 
                        *{5}{X[c, leftsep=12pt]X[c]X[c]}
                        @{}},
             cell{1}{2,5,8,11,14} = {c=3}{c},
             }
   \toprule
        &   Distractor 
            &   &   &   Handled 
                        &   &   &   Average 
                                    &   &   &   Accuracy 
                                                &   &   &   Human
                                                             &   &   \\
    \cmidrule[l=-0.8]{2-4}  \cmidrule[l=-0.8]{5-7} \cmidrule[l=-0.8]{8-10}
    \cmidrule[l=-0.8]{11-13}\cmidrule[l=-0.8]{14-16}
method  & -1:0  & 0:2 & 0:2*    & -1:0  & 0:2   & 0:2*    & -1:0  & 0:2 & 0:2*    
        & -1:0  & 0:2 & 0:2*    & -1:0  & 0:2   & 0:2*  \\
    \midrule
MOD     &       &     &         &       &       &           &   &   &   
        &       &     &         &       &       &       \\
MTGCN   &       &     &         &       &       &           &   &   &
        &       &     &         &       &       &       \\
CAHMP   &       &     &         &       &       &           &   &   &
        &       &     &         &       &       &       \\
Ours    &       &     &         &       &       &           &   &   &
        &       &     &         &       &       &       \\
w/o clf &       &     &         &       &       &           &   &   &
        &       &     &         &       &       &       \\
w/ GT cl&       &     &         &       &       &           &   &   &
        &       &     &         &       &       &       \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

(红线表示文本块边框)。

编辑(2):
现在,当表格内容更加清晰时,我建议使用 siunitx 库/包并重新设计表格,如下所示:

\documentclass{article}
\usepackage{geometry}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
    \begin{table}
    \centering
    \small
\begin{tblr}{colsep  = {3pt},
             colspec = {@{}  Q[l]
                             X[c, si={table-format=1.1}, leftsep=6pt]
                        *{2}{X[c, si={table-format=1.1}]}
                             X[c, si={table-format=2.1}, leftsep=15pt]
                        *{2}{X[c, si={table-format=2.1}]}
                             X[c, si={table-format=2.1}, leftsep=15pt]
                        *{2}{X[c, si={table-format=2.1}]}
                             X[c, si={table-format=1.2}, leftsep=15pt]
                        *{2}{X[c, si={table-format=1.2}]}
                             X[c, si={table-format=2.1}, leftsep=18pt]
                        *{2}{X[c, si={table-format=2.1}]}
                        @{}},
             cell{1}{2,5,8,11,14} = {c=3}{c},
             row{1,2} = {guard}
             }
   \toprule
        &   Distractor
            &   &   &   Handled
                        &   &   &   Average
                                    &   &   &   Accuracy
                                                &   &   &   Human
                                                             &   &   \\
    \cmidrule[l=-0.8]{2-4}  \cmidrule[l=-0.8]{5-7} \cmidrule[l=-0.8]{8-10}
    \cmidrule[l=-0.8]{11-13}\cmidrule[l=-0.8]{14-16}
method  & -1:0  & 0:2 & 0:2*    & -1:0  & 0:2   & 0:2*    & -1:0  & 0:2 & 0:2*
        & -1:0  & 0:2 & 0:2*    & -1:0  & 0:2   & 0:2*  \\
    \midrule
MOD     &     &     &     &      &      &      &      &      &      &      &      &      &      &      &        \\
MTGCN   &     &     &     &      &      &      &      &      &      &      &      &      &      &      &        \\
CAHMP   &     &     &     &      &      &      &      &      &      &      &      &      &      &      &        \\
Ours    &     &     &     &      &      &      &      &      &      &      &      &      &      &      &        \\
w/o clf &     &     &     &      &      &      &      &      &      &      &      &      &      &      &        \\
w/ GT cl& 0.0 & 0.0 & 0.0 & 48.8 & 97.2 & 90.8 &  8.8 & 32.1 & 28.9 & 1.00 & 1.00 & 1.00 & 14.2 & 52.7 & 45.4   \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

相关内容