paracol 环境中计数器的范围

paracol 环境中计数器的范围

我尝试在 MDPI 文章模板中使用长表,但是它们的编号不正确(它总是从 1 开始)。

到目前为止我尝试过什么?

以下是最小工作示例。我已将模板精简到最低限度,仅添加了必要的内容。

\documentclass{article}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{paracol}
\title{Tables}

\begin{document}
\begin{paracol}{2}
\switchcolumn
\newcounter{yolo}
\newpage
\begin{table}[h!]
    \begin{center}
        \caption{Your first table.}
        \begin{tabular}{l|c|r} % <-- Alignments: 1st column left, 2nd middle and 3rd right, with vertical lines in between
            \textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
            \hline
            a & b & c\\
        \end{tabular}
    \end{center}
\end{table}
\setcounter{yolo}{\thetable}
\theyolo
\end{paracol}


\theyolo
\setcounter{table}{\theyolo}
\begin{longtable}{|l|l|l|}
    \caption{A sample long table.} \\

    \hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
    \endfirsthead
    \multicolumn{3}{c}%
    {{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
    \hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
    \endhead

    \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
    \endfoot

    \endlastfoot

    1 & 2 & 3 \\ \hline
\end{longtable}
\begin{paracol}{2}
\switchcolumn 

\begin{table}[h!]
    \begin{center}
        \caption{Your first table.}
        \begin{tabular}{l|c|r} % <-- Alignments: 1st column left, 2nd middle and 3rd right, with vertical lines in between
            \textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
            \hline
            a & b & c\\
        \end{tabular}
    \end{center}
\end{table}
\setcounter{yolo}{\thetable}
\theyolo
\end{paracol}
\small
\setlength{\arrayrulewidth}{0.2mm}
\renewcommand{\arraystretch}{1.2}
\theyolo
\setcounter{table}{\theyolo}
\begin{longtable}{|l|l|l|}
    \caption{A sample long table.}\\
    \hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
    \endfirsthead

    \multicolumn{3}{c}%
    {{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
    \hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
    \endhead

    \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
    \endfoot

    \endlastfoot

    1 & 2 & 3 \\ \hline
\end{longtable}


\end{document}

我尝试使用一个计数器(在上面的示例中名为 yolo)来保存表的值。然后使用它的值来设置 longtables 的计数器。问题是,出于某种原因,yolo 计数器似乎在paracol环境之外有一个旧值。

为了更好地总结这个问题: 在此处输入图片描述

最后一个数字(红色下划线)应该为 3,但它仍保留旧值。

答案1

对于任何有类似问题的人来说。

答案基于paracol以下软件包文档: https://ctan.math.illinois.edu/macros/latex/contrib/paracol/paracol.pdf (第 10 页 - “本地和全局计数器”)

为了将计数器设置为全局的,需要\globalcounter{table}在文档的序言中写入:。

这样就不需要任何额外的计数器,表和长表被视为相同类型的元素。

使用前面的示例:

\documentclass{article}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{paracol}

\globalcounter{table}
\title{Tables}

\begin{document}
\begin{paracol}{2}
\switchcolumn
%\newcounter{yolo}
\newpage
\begin{table}[h!]
    \begin{center}
        \caption{Your first table.}
        \begin{tabular}{l|c|r} % <-- Alignments: 1st column left, 2nd middle and 3rd right, with vertical lines in between
            \textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
            \hline
            a & b & c\\
        \end{tabular}
    \end{center}
\end{table}
%\setcounter{yolo}{\thetable}
%\theyolo
\end{paracol}


%\theyolo
%\setcounter{table}{\theyolo}
\begin{longtable}{|l|l|l|}
    \caption{A sample long table.} \\

    \hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
    \endfirsthead
    \multicolumn{3}{c}%
    {{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
    \hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
    \endhead
    
    \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
    \endfoot
    
    \endlastfoot
    
    1 & 2 & 3 \\ \hline
\end{longtable}
\begin{paracol}{2}
\switchcolumn 

\begin{table}[h!]
    \begin{center}
        \caption{Your first table.}
        \begin{tabular}{l|c|r} % <-- Alignments: 1st column left, 2nd middle and 3rd right, with vertical lines in between
            \textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
            \hline
            a & b & c\\
        \end{tabular}
    \end{center}
\end{table}
%\setcounter{yolo}{\thetable}
%\theyolo
\end{paracol}
\small
\setlength{\arrayrulewidth}{0.2mm}
\renewcommand{\arraystretch}{1.2}
%\theyolo
%\setcounter{table}{\theyolo}
\begin{longtable}{|l|l|l|}
    \caption{A sample long table.}\\
    \hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
    \endfirsthead
    
    \multicolumn{3}{c}%
    {{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
    \hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
    \endhead
    
    \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
    \endfoot
    
    \endlastfoot
    
    1 & 2 & 3 \\ \hline
\end{longtable}


\end{document}

相关内容