Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

No need of titlesec

\usepackage{etoolbox}
\preto{\chapter}{\stepcounter{tabchapter}}
\newcounter{tabchapter}
\renewcommand*{\thetable}{\arabic{tabchapter}.\arabic{table}}
\renewcommand*{\tableformat}{Tab. \thetable}
share|improve this answer
    
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 '11 at 16:14

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}%
share|improve this answer
    
This will not number tables as <globalchapter>.<table> –  egreg Oct 5 '11 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 '11 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 '11 at 16:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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