[texhax] Counters for tables

Lantz Susan lantzs at tristate.edu
Fri Apr 25 20:23:20 CEST 2008


James,

Having recently just created new environments to distinguish maps and
plates from figures, it seems to me that it would be lot simpler for you
to create a new table environment (for the listings, for instance), but
have the new environment use the same counter that your table
environment uses. Or, to use two different counters and set them equal
every time one of the environments is called, advance the counter you
just used, then (again) set them equal to each other.

Also, you might check if your documentclass supports the \numberwithin
command. For example, with amsbook:

\numberwithin{equation}{chapter} (or section or whatever you choose)
\numberwithin{figure}{chapter}
\numberwithin{table}{chapter}

If you created two new environments---one for figures and one for
listings---then if you decide to add a table at the last minute, you
won't have to redefine everything.

Regards,
Susan

Susan A. Lantz, Ph.D.
Associate Professor of Mechanical Engineering
Tri-State University
lantzs at tristate.edu
 

-----Original Message-----


Message: 6
Date: Thu, 24 Apr 2008 19:16:16 +0100
From: "James Smith" <james.smith at aleph-one.com>
Subject: [texhax] Counters for tables
To: <texhax at tug.org>
Message-ID: <000001c8a637$49b219c0$0300000a at flaptop>
Content-Type: text/plain;	charset="us-ascii"

Hey,

I have used the table environment for both figures and pseudo-code
listings, so I've had to redefine the captions to read `Figure x.x:...'
and `Listing x.x:...' depending on the context. This I managed easily,
but of course the figures and listings were numbered, say...

Figure 1.1
Listing 1.2
Listing 1.3
Figure 1.4

...instead of:

Figure 1.1
Listing 1.1
Listing 1.2
Figure 1.2

I thought the smartref package would allow me to overcome this without
much programming, maybe I've got the wrong end of the stick, but I've
still had to define separate environments for the tables, incrementing
the counters ``manually'' myself:

+++

\newcounter{pseudoctr}
\newcounter{figurectr}

\addtoreflist{pseudoctr}
\addtoreflist{figurectr}

\newcommand{\resettablecounters}%
{%
    \setcounter{pseudoctr}{0}%
    \setcounter{figurectr}{0}%
}%

\newenvironment{mypseudotable}[1]%
{%
    \addtocounter{pseudoctr}{1}%
    \begin{table}[#1]%
}%
{%
    \end{table}%
    \par%
}%

\newenvironment{myfiguretable}[1]%
{%
    \addtocounter{figurectr}{1}%
    \begin{table}[#1]%
}%
{%
    \end{table}%
    \par%
}%

+++

I call the \resettablecounters command in my custom \chapter command to
reset the counters. I've then had to define dedicated ref commands...

+++

\newcommand{\mypseudoref}[1]{\chapterref{#1}.\pseudoctrref{#1}}
\newcommand{\myfigureref}[1]{\chapterref{#1}.\figurectrref{#1}}

+++

...and redefine the captions...

+++

\usepackage[labelformat=empty]{caption}

\newcommand{\mypseudocaption}[1]%
{%
    \vspace{-1.6em}%
    \caption{Listing \thechapter.\thepseudoctr: \it#1}%
}%

\newcommand{\myfigurecaption}[1]%
{%
    \vspace{-1.6em}%
    \caption{Figure \thechapter.\thefigurectr: \it#1}%
}%

+++

Have a made a meal of this? I accept that I can practically halve the
number of newly created commands and environments by passing a second
argument to differentiate between the pseudo-code listings and figures
but before I attempt this I want to know whether I'm barking up the
wrong tree...

Any help would be greatly appreciated.

Kind regards,

James



More information about the texhax mailing list