LaTex 跳过数字计数

LaTex 跳过数字计数

我在图形环境中使用该功能时遇到了麻烦\label。最初,我使用的代码会将第 4 节中的图 1 标记为图 41。我找到了这个解决方案:https://stackoverflow.com/questions/3865036/using-a-single-count-for-figures-and-tables-in-latex?rq=1,并且我实现了它,但是现在遇到了 LaTex 以两位为单位计数的问题。

\begin{filecontents*}{dummy.csv}
    Col1,Col2,Col3
    34,54,14
    63,40,93
    39,56,88
    15,42,85
    49,10,16
    89,94,59
    42,79,76
    42,90,35
    13,53,13
    10,60,37
    29,38,34
\end{filecontents*}

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

\makeatletter
\renewcommand*{\thetable}{\arabic{table}}
\renewcommand*{\thefigure}{\arabic{figure}}
\let\c@table\c@figure
\makeatother 

\begin{document}
    \section{Section 1}
    \subsection{Sample 1}
    \begin{figure}[ht!]
        \caption{This should be table 1}
        \label{This should be table 1}
        \csvreader[
        longtable=lrrrr,
    table head=
    \toprule\bfseries Col1 &\bfseries Col2 &\bfseries  Col3\\ \midrule\endhead
    \bottomrule\endfoot,
    late after line=\\,
    before reading={\catcode`\#=12},after reading={\catcode`\#=6}
    ]{dummy.csv}{1=\One,2=\Two, 3=\Three}{\One & \Two & \Three}
\end{figure}

\begin{figure}[ht!]
    \caption{This should be table 2}
    \label{This should be table 2}
    \csvreader[
    longtable=lrrrr,
    table head=
    \toprule\bfseries Col4 &\bfseries Col5 &\bfseries  Col6\\ \midrule\endhead
    \bottomrule\endfoot,
    late after line=\\,
    before reading={\catcode`\#=12},after reading={\catcode`\#=6}
    ]{dummy.csv}{1=\One,2=\Two, 3=\Three}{\One & \Two & \Three}
\end{figure}

\section{Section 2}\label{section 2}
\subsection{sample 2}
\begin{figure}[ht!]
    \caption{This should be table 3}
    \label{This should be table 3}
    \csvreader[
    longtable=lrrrr,
    table head=
    \toprule\bfseries Col7 &\bfseries Col8 &\bfseries  Col9\\ \midrule\endhead
    \bottomrule\endfoot,
    late after line=\\,
    before reading={\catcode`\#=12},after reading={\catcode`\#=6}
    ]{dummy.csv}{1=\One,2=\Two, 3=\Three}{\One & \Two & \Three}
\end{figure}
\end{document} 

答案1

这是因为您使用longtable。Alongtable应用作非浮动,因为它设置在一页上,并且应滚动到后续页面。使用它们\caption必然包括使用 。因此,即使您没有将 包括\caption在 中longtable(源自\csvreader[longtable=..., ...]),它也会递增计数器figure

由于不可能longtable在浮点数内部按预期工作,因此最好使用以下tabular选项:

在此处输入图片描述

\begin{filecontents*}{dummy.csv}
    Col1,Col2,Col3
    34,54,14
    63,40,93
    39,56,88
    15,42,85
    49,10,16
    89,94,59
    42,79,76
    42,90,35
    13,53,13
    10,60,37
    29,38,34
\end{filecontents*}

\documentclass{article}

\usepackage{csvsimple,booktabs}

\makeatletter
\renewcommand*{\thetable}{\arabic{table}}
\renewcommand*{\thefigure}{\arabic{figure}}
\let\c@table\c@figure
\makeatother 

\begin{document}

\section{Section 1}

\begin{figure}[ht!]
  \centering
  \caption{This should be table 1}
  \csvreader[
    tabular=lrrrr,
    table head=
      \toprule\bfseries Col1 & \bfseries Col2 & \bfseries  Col3 \\ \midrule
      \bottomrule,
    late after line=\\,
    before reading={\catcode`\#=12},
    after reading={\catcode`\#=6}
  ]{dummy.csv}
    {1=\One,2=\Two, 3=\Three}{\One & \Two & \Three}
\end{figure}

\begin{figure}[ht!]
  \centering
  \caption{This should be table 2}
  \csvreader[
    tabular=lrrrr,
    table head=
      \toprule\bfseries Col4 & \bfseries Col5 & \bfseries  Col6 \\ \midrule
      \bottomrule,
    late after line=\\,
    before reading={\catcode`\#=12},
    after reading={\catcode`\#=6}
  ]{dummy.csv}
    {1=\One,2=\Two, 3=\Three}{\One & \Two & \Three}
\end{figure}

\section{Section 2}

\begin{figure}[ht!]
  \centering
  \caption{This should be table 3}
  \csvreader[
    tabular=lrrrr,
    table head=
      \toprule\bfseries Col7 & \bfseries Col8 & \bfseries  Col9 \\ \midrule
      \bottomrule,
    late after line=\\,
    before reading={\catcode`\#=12},
    after reading={\catcode`\#=6}
  ]{dummy.csv}
    {1=\One,2=\Two, 3=\Three}{\One & \Two & \Three}
\end{figure}

\end{document}

我还删除了和里面的\endhead\endfoot定义table headlate after line

相关内容