为什么我的表格上方有“[htbp]”?

为什么我的表格上方有“[htbp]”?

下面是 Table 的源代码, 表示[htbp]它的排版方式。运行这段代码时,[htbp]会在表格正上方打印 ,如果将 htbp 替换为其他属性,数字也会打印出来。除非我把 去掉[],否则会导致我的排版很差。

The details of the datasets are listed in Table \ref{tab:addlabel}.

\begin{table}[htbp]
  \centering 
  \caption{Details of benchmark datasets}
    \begin{tabular}{llllllll}
    \toprule
    No.   & Dataset &       &       & \multicolumn{2}{l}{No. of instance} & \multicolumn{2}{c}{No. of features} \\
    \midrule
    1     & \multicolumn{3}{l}{Electrical Grid Data} & \multicolumn{2}{l}{10000} & \multicolumn{2}{l}{14} \\
    2     & \multicolumn{3}{l}{Online Shoppers} & \multicolumn{2}{l}{12330} & \multicolumn{2}{l}{18} \\
    3     & \multicolumn{3}{l}{Dry Bean} & \multicolumn{2}{l}{13611} & \multicolumn{2}{l}{17} \\
    4     & \multicolumn{3}{l}{MAGIC Telescope} & \multicolumn{2}{l}{19020} & \multicolumn{2}{l}{11} \\
    5     & \multicolumn{3}{l}{Letter Recognition} & \multicolumn{2}{l}{20000} & \multicolumn{2}{l}{16} \\
    6     & \multicolumn{3}{l}{Avila} & \multicolumn{2}{l}{20867} & \multicolumn{2}{l}{10} \\
    7     & \multicolumn{3}{l}{Default of Credit Card} & \multicolumn{2}{l}{30000} & \multicolumn{2}{l}{24} \\
    8     & \multicolumn{3}{l}{Bank Marketing} & \multicolumn{2}{l}{45211} & \multicolumn{2}{l}{17} \\
    9     & \multicolumn{3}{l}{Secondary Mushroom} & \multicolumn{2}{l}{61069} & \multicolumn{2}{l}{21} \\
    10    & \multicolumn{3}{l}{Clickstream Data} & \multicolumn{2}{l}{165474} & \multicolumn{2}{l}{14} \\
    11    & \multicolumn{3}{l}{Diabetes Health} & \multicolumn{2}{l}{253680} & \multicolumn{2}{l}{22} \\
    12    & \multicolumn{3}{l}{Linkage Comparison} & \multicolumn{2}{l}{574913} & \multicolumn{2}{l}{12} \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%

答案1

就像@Zarko 所做的那样他的回答,我会S为第三列(实际列)使用列类型。此外,我会对表格的数据行应用一些视觉分组,并为表格的标题行提供更多结构。后一种做法的一个附带好处是表格变得更紧凑,从而增强了整体可读性。

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx} % for 'S' column type

\begin{document}
The details of the datasets are listed in Table \ref{tab:addlabel}.

\begin{table}[htbp]
  \centering 
  \caption{Details of benchmark datasets\strut}
  \label{tab:addlabel}
    \begin{tabular}{@{} ll S[table-format=6.0] c @{}}
    \toprule
    No. & Dataset & \multicolumn{2}{c@{}}{Number of} \\
    \cmidrule(l){3-4}
    & & {Instances} & Features \\
    \midrule
    1   & Electrical Grid Data   &  10000 & 14 \\
    2   & Online Shoppers        &  12330 & 18 \\
    3   & Dry Bean               &  13611 & 17 \\
    4   & MAGIC Telescope        &  19020 & 11 \\
    \addlinespace
    5   & Letter Recognition     &  20000 & 16 \\
    6   & Avila                  &  20867 & 10 \\
    7   & Default of Credit Card &  30000 & 24 \\
    8   & Bank Marketing         &  45211 & 17 \\
    \addlinespace
    9   & Secondary Mushroom     &  61069 & 21 \\
    10  & Clickstream Data       & 165474 & 14 \\
    11  & Diabetes Health        & 253680 & 22 \\
    12  & Linkage Comparison     & 574913 & 12 \\
    \bottomrule
    \end{tabular}
\end{table}
\end{document}

答案2

  • 我们无法重现您的问题,为此您应该提供 MWE(最小工作示例),这是一个小而完整的文档,我们可以按原样编译
  • 您的表格结构非常坚固。请参阅@Mico 的评论。
  • 可能的重写表,其中使用 tabularray package with librariesbooktabs and siunitx˛,并且对于文档类使用article,是:

编辑:
不知何故,表格的第六行不见了。现在添加了,表格的结构更加复杂了:

\documentclass[12pt]{article}
\usepackage[skip=1ex]{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
The details of the datasets are listed in Table \ref{tab:addlabel}.

    \begin{table}[htbp]
    \centering
    \caption{Details of benchmark datasets}
    \label{tab:addlabel}
\begin{tblr}{colspec = {Q[c, si={table-format=2.0}]
                        l
                        Q[c, si={table-format=6.0}]
                        Q[c, si={table-format=2.0}]
                       },
             row{1}  = {guard}
             rowsep  = 1pt,
             row{eachfour} = {abovesep=1ex},
             }
    \toprule
No. & Dataset                   & No. of instance   
                                            &   No. of features     \\
    \midrule
1   &   Electrical Grid Dat     &    10000  &   14  \\
2   &   Online Shoppers         &    12330  &   18  \\
3   &   Dry Bean                &    13611  &   17  \\
4   &   MAGIC Telescope         &    19020  &   11  \\
5   &   Letter Recognition      &    20000  &   16  \\
7   &   Default of Credit Card  &    30000  &   24  \\
8   &   Bank Marketing          &    45211  &   17  \\
9   &   Secondary Mushroom      &    61069  &   21  \\
10  &   Clickstream Dat         &   165474  &   14  \\
11  &   Diabetes Health         &   253680  &   22  \\
12  &   Linkage Comparison      &   574913  &   12  \\
    \bottomrule
\end{tblr}%
\end{table}%
\end{document}

在此处输入图片描述

注意,表格的重写在任何文档类中都有效,但浮点数的使用table取决于所使用的文档类。请参阅@Clara 评论。

相关内容