1

I use a journal class that creates tables using \tbl macro. The table counters are reset after every section. I need to use the \tbl macro but I also need to not reset table counters when a new section is started but to continuously number the tables throughout my paper. I tried to use chngcntr package and the command \counterwithout{table}{section}, it only works when I ignore the \tbl macro and depend only on the standard table definition.

So when I used the code snippet below, I got continuous table numbering (i.e., Table 1, Table 2, Table 3, ...etc ) regardless of the section number but I lost the properties specified by the journal for the appearance of the table:

\documentclass{Jclass}
\usepackage{chngcntr}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage[extra]{tipa}
\usepackage{blindtext}

\ifpdf%
\usepackage{epstopdf}%
\else%
\fi

\counterwithout{table}{section}

\begin{document}
\section{Section1}
\blindtext

\section{Section2}
\begin{table}[h!]
\centering
  \caption{Table Caption Table Caption Table Caption Table Caption!}
    \label{tab:table1}
    \begin{tabular}{@{\extracolsep{\fill}}llll}
    \hline
    Col1& Col2& Col3& Col4\\
    \hline
    val1& val1&   val1& val1 \\
    val1 & val1 &  val1 & val1\\
    val1 & val1 &  val1 & val1\\
    val1 & val1 &  val1 & val1 \\
    val1 & val1 &  val1 & val1\\
    \hline
    \end{tabular}
\end{table}


\end{document}

When I used the macro as the code snippet below, the table counter was based on the section number!

\documentclass{Jclass}
\usepackage{chngcntr}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage[extra]{tipa}
\usepackage{blindtext}

\ifpdf%
\usepackage{epstopdf}%
\else%
\fi

\counterwithout{table}{section}

\begin{document}
\section{Section1}
\blindtext

\section{Section2}

\begin{table}[h!]
\centering
  \tbl{\caption{Table Caption Table Caption Table Caption Table Caption!}
    \label{tab:table1}}
 {\begin{minipage}{25pc}
    \begin{tabular}{@{\extracolsep{\fill}}llll}
    \hline
    Col1& Col2& Col3& Col4\\
    \hline
    val1& val1&   val1& val1 \\
    val1 & val1 &  val1 & val1\\
    val1 & val1 &  val1 & val1\\
    val1 & val1 &  val1 & val1 \\
    val1 & val1 &  val1 & val1\\
    \hline
    \end{tabular}
  \end{minipage}}
  {\begin{tabnote}
  \end{tabnote}}
\end{table}


\end{document}

Here is the class of the journal

How to use \tbl macro with chngcntr package to get continuous table numbering (i.e., Table 1, Table 2, Table 3, ...etc ) or is there any different way that will work with the class of the journal?

4
  • 1
    I can't even compile your document under the current class. Do you have a link to the source for Jclass.cls (not your Dropbox version)? – Werner Mar 9 at 1:43
  • 1
    The class file that you have linked doesn't seem to have any definition that associates the section with \thetable. There are several instances of "Table\ \thetable" but that uses just the value of the table counter. As @Werner suggests, this does not seem to be the class that is producing the numbering you report. – barbara beeton Mar 9 at 1:46
  • @Werner I just try and successfully run the class file (version on Dropbox). I appreciate your reply! Many thanks. – Wahedsaw Mar 9 at 4:03
  • @barbara_beeton Exactly, in the class it seems that the value of the table counter is used!! that is why I asked the question I cannot figure it out and I cannot find alternative solution that can be applied. Many thanks for your reply. – Wahedsaw Mar 9 at 4:09
2

I looked at your JClass.cls, which can also be downloaded:

There are no directives causing the table-counter to be reset with each section.

But I found several issues, the second of them distorting the counting of tables:

  1. Line 748: The LaTeX 2ε-kernel-macro \@pushfilename is redefined in a way which is incompatible with more recent LaTeX 2ε-releases.
  2. Line 2742: The macro \tbl typesets things twice, once within \vboxes for measuring, once outside \vboxes. Thus things like \caption which internally step counters are carried out twice. Thus counters get stepped twice which distorts the counting of tables (or whatever floats).
  3. Line 3394: \document carries out \endgroup. With more recent LaTeX 2ε-releases this causes problems as here the \begin-macro itself checks whether the name of the environment is document and if so carries out \endgroup.
  4. \default@color is undefined/not initialized.
  5. JClass.cls does neither contain \ProvidesClass nor contain other ways of recording the version number/release number of the documentclass nor contain a directive \NeedsTeXFormat{LaTeX2e}[<release date>] or the like indicating which LaTeX 2ε-releases and which TeX-engines the class might be compatible to.
  6. In the .cls-file \usepackage is used instead of \RequirePackage.

(I assume this list of issues is not exhaustive.)

Commenting out the redefinition of \@pushfilename and adding a directive to the definition of \tbl for decrementing the table-counter after producing the \vbox for measuring and initializing \default@color and commenting out \endgroup in line 3394 yields the following code which on my system,

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18>

, with xelatex and pdflatex compiles without error-messages and with latex/lualatex yields error-messages about \Hy@colorlink not being defined.

Jclass.cls:

Line 3394:

Replace

\def\document{\endgroup

by

\def\document{%%%\endgroup

Line 2742 ff:

Replace

\def\tbl#1#2#3{%
\global\setbox\tabcapbox\vbox{#1}%
\global\setbox\tabbox\hbox{#2}%
\global\setbox\tabnotebox\vbox{#3}%
\noindent\vbox{%
\tablemove\textwidth%
\advance\tablemove-\wd\tabbox%
\divide\tablemove2%
%\hspace*{\tablemove}
\vbox{%
\hsize\wd\tabbox%
#1%
#2%
#3}}}

by

\def\tbl#1#2#3{%
\global\setbox\tabcapbox\vbox{#1}%
%%%%
% This is a crude and dirty and sloppy workaround:
\addtocounter{table}{-1}%
% If you want to be safe you need a routine which saves values
% of all counters before creating measuring boxes and resets
% all counter values afterwards. Not just counter-values
% need to be taken into account. Everything that must not be
% done twice and that is not delayed until the output-routine
% acts needs to be taken into account.
%%%%
\global\setbox\tabbox\hbox{#2}%
\global\setbox\tabnotebox\vbox{#3}%
\noindent\vbox{%
\tablemove\textwidth%
\advance\tablemove-\wd\tabbox%
\divide\tablemove2%
%\hspace*{\tablemove}
\vbox{%
\hsize\wd\tabbox%
#1%
#2%
#3}}}

Line 748 ff:

Replace

\def\@pushfilename{%
  \xdef\@currnamestack{%
    {\@currname}%
    {\@currext}%
    {\the\catcode`\@}%
    \@currnamestack}}%
\@onlypreamble\@pushfilename%
\@pushfilename%

by

%\def\@pushfilename{%
%  \xdef\@currnamestack{%
%    {\@currname}%
%    {\@currext}%
%    {\the\catcode`\@}%
%    \@currnamestack}}%
%\@onlypreamble\@pushfilename%
%\@pushfilename%

test.tex

\documentclass{Jclass}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage[colorlinks=true]{hyperref}
\usepackage[extra]{tipa}
\usepackage{blindtext}


\ifpdf%
\usepackage{epstopdf}%
\else%
\fi

%\counterwithout{table}{section}

\makeatletter
\let\default@color\current@color
%  In case you want table-counter to be reset when section-counter is stepped
%  and \thetable to yield both the value of section-counter and the value of the
% table-counter:
%\@addtoreset{table}{section}%
%\renewcommand\thetable{\thesection.\@arabic\c@table}%
\makeatother

\color{black}

\begin{document}
\section{Section1}
\blindtext

\section{Section2}

\begin{table}[h!]
\centering
  \tbl{\caption{Table Caption Table Caption Table Caption Table Caption!}
    \label{tab:table1}}
 {\begin{minipage}{25pc}
    \begin{tabular}{@{\extracolsep{\fill}}llll}
    \hline
    Col1& Col2& Col3& Col4\\
    \hline
    val1& val1&   val1& val1 \\
    val1 & val1 &  val1 & val1\\
    val1 & val1 &  val1 & val1\\
    val1 & val1 &  val1 & val1 \\
    val1 & val1 &  val1 & val1\\
    \hline
    \end{tabular}
  \end{minipage}}
  {\begin{tabnote}
  \end{tabnote}}
\end{table}


\end{document}

After doing the modifications described above, compiling test.tex via xelatex or pdflatex on my system yields the following output:

enter image description here

2
  • I really appreciate your answer. Indeed, it is not mine but a class given by the Journal where I would like to submit my paper. I have been working on it for at least one week trying to figure out why I got such results (e.g., problems with continuous table numbering, problems when updating some packages). Many thank for your time and effort. – Wahedsaw Mar 9 at 14:34
  • 1
    @Wahedsaw You are welcome. :-) In the past I several times also stumbled over the problem of counters being incremented but not being reset when creating boxes not for typesetting but for measuring. The journal needs to be informed about the code of its documentclass not being compatible to recent LaTeX 2e-kernels and only working with pdfLaTeX-engines and XeLaTeX-engines but not working with LaTeX-engines/LuaTeX-engines. – Ulrich Diez Mar 9 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.