表格编号未正确递增

表格编号未正确递增
\documentclass{book}

\usepackage{array}
\usepackage{mdframed}
\usepackage{multirow}
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25}
\usepackage{float}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{longtable}

\newmdenv[%
linecolor=ocre,
backgroundcolor=ocre!10,
linewidth=1pt]
{Tablebox}   


\newenvironment{mytablebox}
{
    \begin{Tablebox}
        
    }
    {
    \end{Tablebox}
}



\begin{document}
    The various activities which are performed in the Crane shop are given in table \ref{table:crane_shop_activities}.
    \begin{mytablebox}
        %\begin{table}[H]
        \centering
        \captionof{table}{Crane shop activities.}
            \label{table:crane_shop_activities}
        \begin{longtable}{|m{2cm}| m{4cm}| m{4cm}|}
            \hline
            \textbf{Category} & \textbf{Types} & \textbf{Activities}\\
            \hline
            \multirow{3}{*}{Tower Car} & Mark II, III, IV & \multirow{3}{4cm}{Earlier Manufacturing, currently only POH}\\
            \cline{2-2}
            & DHTC (Diesel Hydraulic Tower Car) & \\
            \cline{2-2}
            & 8 Wheeler &\\
            \hline
            \multirow{2}{*}{20T Crane} & Mechanical & \multirow{2}{4cm}{Both Manufacturing and POH}\\
            \cline{2-2}
            & Hydraulic (retrofitting of mechanical superstructure with hydraulic one) & \\
            \hline
            \multirow{2}{*}{140T Crane} & Old Design Crane & POH, MLR, SP MLR\\
            \cline{2-3}
            & New Design Crane & Manufacturing, POH, MLR, SP MLR\\
            \hline
        
        \end{longtable}
        %\end{table}
    \end{mytablebox}
    
    Activities related to 140T crane are given in detail in table \ref{table:140T_activities}.
    \begin{mytablebox}
        \begin{table}[H]
            \caption{140T Crane activities.}
            \begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}
                \hline
                1$^{st}$ POH & After 8 yrs\\
                \hline
                2$^{nd}$ POH & After 16 yrs\\
                \hline
                MLR & After 22 yrs\\
                \hline
                SP MLR & After 30 yrs\\
                \hline
                SR (Special Repair) & Accidental and unpredictable\\
                \hline
            \end{tabular}
            \label{table:140T_activities}
        \end{table}
    \end{mytablebox}

    
    
\end{document}

第二张桌子的桌子号错误

2 号桌子变成了 3 号桌子。如何纠正这个问题?

答案1

恐怕没有委婉的方式来表达这一点:你滥用了longtabletable环境\captionof

  • 如果您使用longtable环境,不使用语句\captionof{table}{...}。请改用标准\caption语句。

  • 如果你要将一些表格材料封装在mytablebox环境中,不使用环境table\caption语句。相反,应该去掉table包装器,应用\centering指令,然后使用\captionof语句。


在此处输入图片描述

\documentclass{book}
\usepackage{array}
\setlength\extrarowheight{2pt} % for a more "open" look
\usepackage{mdframed}
\usepackage{multirow}
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25}
\usepackage{float}
\usepackage[skip=0.333\baselineskip]{caption}
\usepackage{booktabs}
\usepackage{longtable}

\newmdenv[%
    linecolor=ocre,
    backgroundcolor=ocre!10,
    linewidth=1pt]
  {Tablebox}   
\newenvironment{mytablebox}
   {\begin{Tablebox}}{\end{Tablebox}}

\begin{document}
Various activities performed in the Crane shop are given in table \ref{table:crane_shop_activities}.
    \begin{mytablebox}
    \begin{longtable}{|m{2cm}| m{4cm}| m{4cm}|}
        \caption{Crane shop activities.}
        \label{table:crane_shop_activities}\\
        \hline
        \textbf{Category} & \textbf{Types} & \textbf{Activities}\\
        \hline
        \multirow{3}{*}{Tower Car} & Mark II, III, IV & 
        \multirow{3}{4cm}{Earlier Manufacturing, currently only POH}\\
        \cline{2-2}
        & DHTC (Diesel Hydraulic Tower Car) & \\
        \cline{2-2}
        & 8 Wheeler &\\
        \hline
        \multirow{2}{*}{20T Crane} & Mechanical & 
        \multirow{2}{4cm}{Both Manufacturing and POH}\\
        \cline{2-2}
        & Hydraulic (retrofitting of mechanical superstructure with hydraulic one) & \\
        \hline
        \multirow{2}{*}{140T Crane} & Old Design Crane & POH, MLR, SP MLR\\
        \cline{2-3}
        & New Design Crane & Manufacturing, POH, MLR, SP MLR\\
        \hline
    \end{longtable}
    \end{mytablebox}

Activities related to 140T crane are given in detail in table \ref{table:140T_activities}.
    \begin{mytablebox}
    \centering % <-- new!
    %\begin{table}[H] %% do NOT use a 'table' env.
        \captionof{table}{140T Crane activities.} %% use '\captionof', not '\caption'
        \label{table:140T_activities}
        \begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}
        \hline
        1$^{st}$ POH & After 8 yrs\\
        \hline
        2$^{nd}$ POH & After 16 yrs\\
        \hline
        MLR & After 22 yrs\\
        \hline
        SP MLR & After 30 yrs\\
        \hline
        SR (Special Repair) & Accidental and unpredictable\\
        \hline
        \end{tabular}
    %\end{table}
    \end{mytablebox}

\end{document}

答案2

解决方案longtabular

您必须在 里面写入\captionand 。\labellongtabular

\documentclass{book}

\usepackage{array}
\usepackage{mdframed}
\usepackage{multirow}
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25}
\usepackage{float}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{longtable}

\newmdenv[%
linecolor=ocre,
backgroundcolor=ocre!10,
linewidth=1pt]
{Tablebox}   

\newenvironment{mytablebox}
{
    \begin{Tablebox}
}
{
    \end{Tablebox}
}

\begin{document}
    The various activities which are performed in the Crane shop are given in table \ref{table:crane_shop_activities}.
    \begin{mytablebox}
        \centering
        \begin{longtable}{|m{2cm}| m{4cm}| m{4cm}|}
            \caption{Crane shop activities.}
            \label{table:crane_shop_activities}\\
            \hline
            \textbf{Category} & \textbf{Types} & \textbf{Activities}\\
            \hline
            \multirow{3}{*}{Tower Car} & Mark II, III, IV & \multirow{3}{4cm}{Earlier Manufacturing, currently only POH}\\
            \cline{2-2}
            & DHTC (Diesel Hydraulic Tower Car) & \\
            \cline{2-2}
            & 8 Wheeler &\\
            \hline
            \multirow{2}{*}{20T Crane} & Mechanical & \multirow{2}{4cm}{Both Manufacturing and POH}\\
            \cline{2-2}
            & Hydraulic (retrofitting of mechanical superstructure with hydraulic one) & \\
            \hline
            \multirow{2}{*}{140T Crane} & Old Design Crane & POH, MLR, SP MLR\\
            \cline{2-3}
            & New Design Crane & Manufacturing, POH, MLR, SP MLR\\
            \hline
        \end{longtable}
    \end{mytablebox}

    Activities related to 140T crane are given in detail in table \ref{table:140T_activities}.
    \begin{mytablebox}
        \begin{table}[H]
            \caption{140T Crane activities.}
            \begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}
                \hline
                1$^{st}$ POH & After 8 yrs\\
                \hline
                2$^{nd}$ POH & After 16 yrs\\
                \hline
                MLR & After 22 yrs\\
                \hline
                SP MLR & After 30 yrs\\
                \hline
                SR (Special Repair) & Accidental and unpredictable\\
                \hline
            \end{tabular}
            \label{table:140T_activities}
        \end{table}
    \end{mytablebox}
\end{document}

在此处输入图片描述

无解longtabular

如果您使用tabular而不是 ,longtable它就会起作用。为了避免不同的间距,您\captionof也应该对第二个表使用。

\documentclass{book}

\usepackage{array}
\usepackage{mdframed}
\usepackage{multirow}
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25}
\usepackage{float}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{longtable}

\newmdenv[%
linecolor=ocre,
backgroundcolor=ocre!10,
linewidth=1pt]
{Tablebox}   

\newenvironment{mytablebox}
{
    \begin{Tablebox}
}
{
    \end{Tablebox}
}

\begin{document}
    The various activities which are performed in the Crane shop are given in table \ref{table:crane_shop_activities}.
    \begin{mytablebox}
        \centering
        \captionof{table}{Crane shop activities.}
        \label{table:crane_shop_activities}
        \begin{tabular}{|m{2cm}| m{4cm}| m{4cm}|}
            \hline
            \textbf{Category} & \textbf{Types} & \textbf{Activities}\\
            \hline
            \multirow{3}{*}{Tower Car} & Mark II, III, IV & \multirow{3}{4cm}{Earlier Manufacturing, currently only POH}\\
            \cline{2-2}
            & DHTC (Diesel Hydraulic Tower Car) & \\
            \cline{2-2}
            & 8 Wheeler &\\
            \hline
            \multirow{2}{*}{20T Crane} & Mechanical & \multirow{2}{4cm}{Both Manufacturing and POH}\\
            \cline{2-2}
            & Hydraulic (retrofitting of mechanical superstructure with hydraulic one) & \\
            \hline
            \multirow{2}{*}{140T Crane} & Old Design Crane & POH, MLR, SP MLR\\
            \cline{2-3}
            & New Design Crane & Manufacturing, POH, MLR, SP MLR\\
            \hline
        \end{tabular}
    \end{mytablebox}

    Activities related to 140T crane are given in detail in table \ref{table:140T_activities}.
    \begin{mytablebox}
        \captionof{table}{140T Crane activities.}
        \label{table:140T_activities}
        \begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}
            \hline
            1$^{st}$ POH & After 8 yrs\\
            \hline
            2$^{nd}$ POH & After 16 yrs\\
            \hline
            MLR & After 22 yrs\\
            \hline
            SP MLR & After 30 yrs\\
            \hline
            SR (Special Repair) & Accidental and unpredictable\\
            \hline
        \end{tabular}
    \end{mytablebox}
\end{document}

在此处输入图片描述

相关内容