4個表中的表編號不匹配,其中一個是longtable

4個表中的表編號不匹配,其中一個是longtable

這裡有 4 張桌子。表1,3和4的標題和標籤輸出為表1,2和3。如何依序輸出他們的表格標籤和標題?

\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我獲得了預期的正確結果:

在此輸入影像描述

如您所見,罪魁禍首是長表代碼。在 a 中,longtable您不能包含tabular( 或其他表環境,如您所做的那樣。After\begin{longtable}應遵循列規範 ( clr) p{...}。請參閱下面的 MWE。

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}

相關內容