如何对表和长表使用不同的计数器/表名?

如何对表和长表使用不同的计数器/表名?

我想要的是

表 1:表内容...LongTable 1:longtable 内容...

我得到的是:

表 1:table 内容…表 2:longtable 内容....

例子: 在此处输入图片描述

\documentclass{article}
\usepackage{longtable}

\begin{document}
    \begin{table}
        \centering
        \caption{this is table environment}
        \begin{tabular}{||c c c c||} 
            1 & 6 & 87837 & 787 \\ 
        \end{tabular}
    \end{table}

    \begin{longtable}{||l|c||}
        \caption{this is longtable environment}
        \endfirsthead
        content & 12 \\
    \end{longtable}
\end{document}

答案1

为了使它\listofLTs工作,我不得不对 longtable 进行一些修改。这样使用新的计数器就比来回交换它们更容易了。

\documentclass{article}
\usepackage{longtable}

\usepackage{newfloat}
\DeclareFloatingEnvironment[% counter name is LT
    listname=List of Long Tables,
    name={Long Table},
    fileext=lolt
]{LT}

\usepackage{etoolbox}
\makeatletter
\def\LT@c@ption#1[#2]#3{%
  \LT@makecaption#1\fnum@LT{#3}%
  \def\@tempa{#2}%
  \ifx\@tempa\@empty\else
     {\let\\\space
     \addcontentsline{lolt}{LT}{\protect\numberline{\theLT}{#2}}}%
  \fi}
\patchcmd{\LT@array}{\refstepcounter{table}}{\refstepcounter{LT}}{}{FAILED}
\makeatother

\begin{document}
  \listoftables
  \listofLTs
  
    \begin{table}[ht]
        \centering
        \caption{this is table environment}
        \begin{tabular}{||c c c c||} 
            1 & 6 & 87837 & 787 \\ 
        \end{tabular}
    \end{table}

    \begin{longtable}{||l|c||}
        \caption{this is longtable environment}
        \endfirsthead
        content & 12 \\
    \end{longtable}

\end{document}

如果您加载字幕包,则可以实现更简单的解决方案。

\documentclass{article}
\usepackage{caption}% required
\usepackage{longtable}

\usepackage{newfloat}
\DeclareFloatingEnvironment[% counter name is LT
    listname=List of Long Tables,
    name={Long Table},
    fileext=lolt
]{LT}
\renewcommand{\LTcaptype}{LT}

\begin{document}
  \listoftables
  \listofLTs
  
    \begin{table}[ht]
        \centering
        \caption{this is table environment}
        \begin{tabular}{||c c c c||} 
            1 & 6 & 87837 & 787 \\ 
        \end{tabular}
    \end{table}

    \begin{longtable}{||l|c||}
        \caption{this is longtable environment}
        \endfirsthead
        content & 12 \\
    \end{longtable}

\end{document}

答案2

默认情况下,长表在标题方面与表格的行为相同,因此需要进行一些调整。

情况 1:使用同一个计数器

只需使用caption包来更改长表的名称,如下所示:

\documentclass{article}
\usepackage{longtable}
\usepackage{caption}
\captionsetup[longtable]{name={Long Table}}

\begin{document}
    \begin{table}
        \centering
        \caption{this is table environment}
        \begin{tabular}{||c c c c||} 
            1 & 6 & 87837 & 787 \\ 
        \end{tabular}
    \end{table}

    \begin{longtable}{||l|c||}
        \caption{this is longtable environment}
        \endfirsthead
        content & 12 \\
    \end{longtable}
\end{document}

这使

方法 1

情况 2:使用不同的计数器(一种新型浮点数)

使用newfloat包和DeclareFloatingEnvironment你想要的环境。这是代码

\documentclass{article}
\usepackage{longtable}

\usepackage{float}
\usepackage{newfloat}

\DeclareFloatingEnvironment[
    listname=List of Long Tables,
    name=LongTable,
    placement=tbhp
]{LT}

\begin{document}
    \begin{table}
        \centering
        \caption{this is table environment}
        \begin{tabular}{||c c c c||} 
            1 & 6 & 87837 & 787 \\ 
        \end{tabular}
    \end{table}

    \begin{LT}
        \caption{this is longtable environment}
        \begin{longtable}[H]{||l|c||}
            \endfirsthead
            content & 12 \\
        \end{longtable}
    \end{LT}
\end{document}

结果:

结果 2

相关内容