制作不影响桌子编号的长桌

制作不影响桌子编号的长桌

我想用 来longtable列出论文前言中的缩写。我没有给它加标题,所以它(理所当然地)不会出现在我的表格列表中。然而,它取消其余表格的编号 - 换句话说,本应是表 1 的表格现在被加上标题并在表格列表中列为表 2。

\documentclass{report}
\usepackage{longtable}
\begin{document}
\listoftables

The table I don't want to be numbered:
\begin{longtable}{ll}
\textbf{acac} & acetylacetonate \\
\textbf{Ar} & aryl \\
\end{longtable}

\begin{table}
\begin{center}
\caption{The table that I want to be Table 1}
\begin{tabular}{|c|c|}
\hline
column 1 & column 2 \\ \hline
77 & 43 \\ \hline
\end{tabular}
\end{center}
\end{table} 

\end{document}

防止发生这种错误编号的最佳方法是什么?我考虑为这种情况创建一个新的浮动环境,但这似乎不太优雅。

答案1

长表添加后将\addtocounter{table}{-1}减少计数器表的临时值:

\documentclass{report}
\usepackage{longtable}
\begin{document}
\listoftables

The table I don't want to be numbered:
\begin{longtable}{ll}
\textbf{acac} & acetylacetonate \\
\textbf{Ar} & aryl \\
\end{longtable}
    \addtocounter{table}{-1}%<-- decrement table counter

\begin{table}
\begin{center}
\caption{The table that I want to be Table 1}
\begin{tabular}{|c|c|}
\hline
column 1 & column 2 \\ \hline
77 & 43 \\ \hline
\end{tabular}
\end{center}
\end{table}

\end{document}

答案2

\addtocounter{table}{-1}很简单,\SuspendCounters{table}assoccnt包装(带选项)开始也可以。然后在适当的地方globalsuspend使用。\ResumeSuspendedCounters

\documentclass{report}
\usepackage{longtable}
\usepackage[globalsuspend=true]{assoccnt}


\SuspendCounters{table}
\begin{document}
\listoftables

The table I don't want to be numbered:
\begin{longtable}{ll}
\textbf{acac} & acetylacetonate \\
\textbf{Ar} & aryl \\
\end{longtable}
\ResumeSuspendedCounters

\begin{table}
\begin{center}
\caption{The table that I want to be Table 1}
\begin{tabular}{|c|c|}
\hline
column 1 & column 2 \\ \hline
77 & 43 \\ \hline
\end{tabular}
\end{center}
\end{table} 


\end{document}

在此处输入图片描述

答案3

不确定软件包作者是否会批准,但这应该可行:

  1. 在代码中\longtable,将新条件设置为 false
  2. 在代码中\LT@caption,将此条件设置为 true
  3. 在 的代码中\endlongtable,检查条件的值:如果是true,则 中已排版标题longtable,则不执行任何操作;如果是false,则未使用任何标题,将table计数器降低。
\documentclass{report}
\usepackage{longtable}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\LT@caption}
  {\bgroup}
  {\bgroup\global\LTpatch@captiontrue}
  {}{}
\patchcmd{\longtable}
  {\par}
  {\par\global\LTpatch@captionfalse}
  {}{}
\apptocmd{\endlongtable}
  {\ifLTpatch@caption\else\addtocounter{table}{-1}\fi}
  {}{}
\newif\ifLTpatch@caption
\makeatother

\begin{document}
\listoftables

\bigskip

The table I don't want to be numbered:
\begin{longtable}{ll}
\textbf{acac} & acetylacetonate \\
\textbf{Ar} & aryl \\
\end{longtable}

\begin{table}[htp]
\centering
\caption{The table that I want to be Table 1}
\medskip
\begin{tabular}{|c|c|}
\hline
column 1 & column 2 \\ \hline
77 & 43 \\ \hline
\end{tabular}
\end{table} 

\end{document}

在此处输入图片描述

相关内容