4 个表中的表编号不匹配,其中一个是长表

4 个表中的表编号不匹配,其中一个是长表

这里有4个表。表1、3和4的标题和标签输出为表1、表2和表3。但是表2是一个长表,它的表标签没有显示。如何按顺序输出它们的表标签和标题?

\begin{table}[h]
\caption{first table}
\label{tab:1}
\setlength\tabcolsep{0pt} 
\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}} |l|c|}
\toprule
     some codes
\midrule
  some codes
\end{tabular*}
\smallskip
\scriptsize
\end{table}
\\
\begin{longtable}
%\setlength 
\setlength\tabcolsep{0pt}
\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}} |l|c|r|}
\caption{second table}\label{tab:2}\\
\toprule
some codes
   \midrule
    some codes
    \bottomrule
    
 \hline   
\end{tabular*}

\smallskip
\scriptsize
\end{longtable}
\\
\begin{table}[h]
\begin{center}
\caption{Third table}
\label{tab:3}
\begin{tabular}{|l|c|c|c|c|c|r|} \hline
some codes
  \hline
\end{tabular}
\smallskip
\scriptsize
\end{center}
\end{table}
\begin{table}[h]
\begin{center}
\caption{Summary of overall query result}
\label{tab:4}
\begin{tabular}{|l|c|c|r|} \hline
some codes

\end{tabular}
\smallskip
\scriptsize
\end{center}
\end{table}\\

答案1

合并您的代码片段后,纠正使用错误语法,longtable我获得了预期的正确结果:

在此处输入图片描述

如您所见,罪魁祸首是长表的代码。在 中,您不能像在 中一样longtable包含(或其他表环境。之后应遵循列规范(、或)。请参阅下面的 MWE。tabular\begin{longtable}clrp{...}

MWE 产生的结果表明:

\documentclass{article}
\usepackage{array, booktabs, longtable}

\begin{document}
    \begin{table}[ht]
\caption{first table}
\label{tab:1}
\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}} |l|c|}
\toprule
     some codes &   some codes  \\
\bottomrule
\end{tabular*}
    \end{table}

\begin{longtable}{|l|c|r|}
\caption{second table}
\label{tab:2}\\
    \toprule
     some codes &   some codes  \\
    \bottomrule
\end{longtable}

    \begin{table}[ht]
\centering
\caption{Third table}
\label{tab:3}
\begin{tabular}{|l|c|c|c|c|c|r|} \hline
1 & 2 & 3 & 4 & 5 & 6 & 7   \\
  \hline
\end{tabular}
    \end{table}

    \begin{table}[ht]
\centering
\caption{Summary of overall query result}
\label{tab:4}
\begin{tabular}{|l|c|c|r|} \hline
1 & 2 & 3 & 4   \\
  \hline
\end{tabular}
    \end{table}
\end{document}

相关内容