4

My document is a (scr)book and I'm talking of parts and chapters here, but I think the underlying question is pretty generic.

  • I want tables in the book to be enumerated continuously, in a chapter.table way.

  • I reset the chapter counter for each part of the book using a custom-made MyPart command, which is necessary for several other reasons not presented here.

  • However, I do not want to reset the table numbering. (I.e., the "chapter" part in the table number should keep a running total of chapters across part boundaries.)

I got it working by defining a counter tabchapter, and bumping that one manually whenever a new \chapter is declared. I wanted to avoid having to declare something like \MyChapter solely for this purpose, but I was not satisfied with my solution:

\documentclass[open=any]{scrbook}

\usepackage{titlesec}

\newcounter{tabchapter}
\renewcommand*{\thetable}{\arabic{tabchapter}.\arabic{table}}
\renewcommand*{\tableformat}{Tab. \thetable}

%% Ugly hijacking of a formatting command to follow...
\titleformat{\chapter}
    {\addtocounter{tabchapter}{1}\Huge\bfseries}   %% <<----  *COUGH*...
    {}
    {0pt}
    {}

\newcommand{\MyPart}[1]{
    \setcounter{chapter}{0}
    \refstepcounter{part}
}

\newcommand{\exampletable}[1]{
    \begin{table}
        \caption{#1}
        \begin{tabular}{c}
            Nothing much.
        \end{tabular}
    \end{table}
}

\begin{document}
\MyPart{Book One}
\chapter{The First}
\exampletable{Some Table}
\chapter{The Second}
\exampletable{Other Table}
\MyPart{Book Two}
\chapter{The First of the Second}
\exampletable{Yet Another Table}
\end{document}

Is there another way to have some counter incremented whenever a standard sectioning command is called (i.e., somehow "linking" it to the standard counter)? Other than wrapping the bump in a custom \MyChapter command?

2 Answers 2

10

No need of titlesec

\usepackage{etoolbox}
\preto{\chapter}{\stepcounter{tabchapter}}
\newcounter{tabchapter}
\renewcommand*{\thetable}{\arabic{tabchapter}.\arabic{table}}
\renewcommand*{\tableformat}{Tab. \thetable}
1
  • That's it! That's exactly the thing I've been looking for! It struck me as so "unexotic" a requirement that there had to be a less hack-ish way to do it... ;-)
    – DevSolar
    Oct 5, 2011 at 16:14
2

The chngcntr package provides \counterwithin and \counterwithout that you can use to add/remove elements that force counter resetting. You're probably after

\usepackage{chngcntr}% http://ctan.org/pkg/chngcntr
...
\counterwithout{table}{chapter}%
\counterwithout{table}{part}%
3
  • This will not number tables as <globalchapter>.<table>
    – egreg
    Oct 5, 2011 at 16:08
  • Yes-ish... I want the running chapter total in the table number, i.e. akin to chapter.table, with resetting of table with each chapter. What I don't want is resetting the chapter part... but only for the purpose of table numbering. So I do need a custom counter of sorts, which gets incremented with each \chapter, but not reset with a new \part (or rather, \MyPart). But this package opens up several new ways to try it, so I'll see what inspiration brings up. ;-)
    – DevSolar
    Oct 5, 2011 at 16:08
  • Oh, see what's going on now - it wasn't clear to me from reading the original question text. The MWE gives a better view of what is needed.
    – Werner
    Oct 5, 2011 at 16:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .