[comp.text] Page numbering by chapter in LaTeX

swonk@ccicpg.UUCP (Glen Swonk) (07/14/89)

I would like to write a large document in pieces,
so that each chapter can be compiled/debugged separately.

What I would like is a page numbering scheme that the page number
would restart at the beginning of each chapter (like it
does in some technical manuals).

For example:

	Chapter1: Intro
		pages 1-1 thru 1-10

	Chapter2: Operation
		pages 2-1 thru 2-12

	Chapter3: Maintenance
		pages 3-1 thru 3-33

Of course, I would like to generate a table of contents
that reflect the page numbering style.


Any help is appreciated.
thanks

-- 
Glenn L. Swonk		CCI Computers 
(714)458-7282		9801 Muirlands Boulevard
			Irvine, CA 92718
uunet!ccicpg!swonk

holtz@sce.carleton.ca (Neal Holtz) (07/17/89)

In article <31495@ccicpg.UUCP> swonk@ccicpg.UUCP (Glen Swonk) writes:
>I would like to write a large document in pieces,
>so that each chapter can be compiled/debugged separately.
>
>What I would like is a page numbering scheme that the page number
>would restart at the beginning of each chapter ... [stuff deleted]

	The way I did it was to redefine the LaTeX \chapter command
	to execute a user-defined "hook" at the right place for each
	new chapter (i.e., after the double page has been flushed, but 
	before the title is set), as shown in this fragment from
	my style file (which modifies the "book" style):


%%%%%%%%%%%%%%%% begin "mybook.sty" %%%%%%%%%%%%%%%%

\input book.sty
		% add "\everychapter" hook for use at every \chapter command
\def\everychapter#1{\gdef\@everychapter{#1}}
\def\@everychapter{}
		% redefine the \chapter command to include the "hook"
\def\chapter{\cleardoublepage \thispagestyle{plain} \global\@topnum\z@
 \@afterindentfalse \@everychapter \secdef\@chapter\@schapter} 

%%%%%%%%%%%%%%%% end "mybook.sty" %%%%%%%%%%%%%%%%


	Then I can use that hook to automatically reset the page counter 
	at the beginning of every chapter.  In the following example,
	note that the preface section uses lower cases roman numerals
	for page numbers (as set by the first "\renewcommand"), while 
	the main body uses chapter--page numbers (as set by the second
	"\renewcommand"):


%%%%%%%%%%%%%%%% begin "thebook.tex" %%%%%%%%%%%%%%%%

\documentstyle{mybook}

\begin{document}

		% preface section - roman numeral page nums
\renewcommand{\thepage}{\roman{page}}
\include{titlepage}

\include{contents}

\include{preface}

		% main body - number pages within chapters
\renewcommand{\thepage}{\thechapter--\arabic{page}}
\everychapter{\setcounter{page}{1}}

\include{introduction} 	% ch1

\include{structural} 	% ch2

\include{surveying} 	% ch3

%% ... etc.

%%%%%%%%%%%%%%%% end "thebook.tex" %%%%%%%%%%%%%%%%


	The "\include"ed files simply start the "\chapter"
	commands -- there is nothing special in them.  And the
	table of contents is correct, automatically.

	By the way, I have a modified version of an old version of an index
	sort/merge program distributed by the Free Software Foundation
	that works with page numbers of this type.  Source
	available, of course.
-- 
------------------------------------------
Prof. Neal Holtz           <holtz@cascade.carleton.ca>
Dept. of Civil Engineering / Carleton University / Ottawa

pyoung@zaphod.axion.bt.co.uk (peter young) (07/18/89)

From article <31495@ccicpg.UUCP>, by swonk@ccicpg.UUCP (Glen Swonk):
> 
> What I would like is a page numbering scheme that the page number
> would restart at the beginning of each chapter (like it
> does in some technical manuals).
> 
In the pre-amble (ie the bit before \begin{document}) change the
command which numbers the pages to 

\renewcommand{\thepage}{\thesection-\arabic{page}}

Then at the beginning of each section reset the page counter to 1 thus

\setcounter{page}{1}

This will cope with sections and will number all the pages in Appendix A
as A-1, A-2 and so on.
It helps if you begin each section on a new page.
 
> Of course, I would like to generate a table of contents
> that reflect the page numbering style.

\tableofcontents can cope with this but it depends where you want your
table of contents to appear and what page number you wish it to be on.
It may be advisable to turn off the page numbering for this page.

The same applies if you have a bibliography - one solution is to issue
another renew command at the start of the bibliography (assuming it is
after all the appendices;

\renewcommand{\thepage}{Bib-\arabic{page}}
\setcounter{page}{1}

Will label all the bibliography pages Bib-1....

Hope this is some help.

Pete 
+---------------------------------------------------------------------+
| Pete Young   E-Mail       :pyoung@axion.bt.co.uk                    |
|              Organisation :British Telecom Research Labs            |
|              BTRL, Rm 313, SSTF, Martlesham Heath, IPSWICH IP5 7RE  |
|              Phone        :  +44 473 645054                         |
+---------------------------------------------------------------------+
|     Healey's Law of Holes:   When you're in one, stop digging.      |
+---------------------------------------------------------------------+

whbr@cgch.UUCP (Hellmuth Broda) (07/25/89)

In article <31495@ccicpg.UUCP> swonk@ccicpg.UUCP (Glen Swonk) writes:
>I would like to write a large document in pieces,
>so that each chapter can be compiled/debugged separately.
>
>What I would like is a page numbering scheme that the page number
>would restart at the beginning of each chapter (like it
>does in some technical manuals).
>
>For example:
>
>	Chapter1: Intro
>		pages 1-1 thru 1-10
>
>	Chapter2: Operation
>		pages 2-1 thru 2-12
>
>	Chapter3: Maintenance
>		pages 3-1 thru 3-33
>
>Of course, I would like to generate a table of contents
>that reflect the page numbering style.
>
>
>Any help is appreciated.
>thanks
>
>-- 
>Glenn L. Swonk		CCI Computers 
>(714)458-7282		9801 Muirlands Boulevard
>			Irvine, CA 92718
>uunet!ccicpg!swonk

We have been using the following approach:


\documentstyle{report}
\title{}
\author{}

\begin{document}
\maketitle
\pagenumbering{Roman}
\tableofcontents
\clearpage
\addcontentsline{toc}{chapter}{\protect\numberline{}{List of tables}}
\listoftables
\clearpage
\typeout{Starting chapter relative page numbering...}%  
\makeatletter%                                        
\def\pagenumbering#1{\global\c@page \@ne%            
   \gdef\thepage{\thechapter -\csname @#1\endcsname \c@page}}% 
\makeatother
\setcounter{page}{1}
\pagenumbering{arabic}%
\chapter{}
\chapter{}
%...
\appendix
\chapter{}
%...
\end{document}

------------
This works with all xrefs, cits etc.  We had to twiggle our local 
makeindex somewhat to have it digest the new page numbers but that
was a job on a few awk scripts.


Hope that helps---Hellmuth Broda

 ___________________________________________________________________________
| Dr.rer.nat. Hellmuth W. Broda |  c/o CIBA-GEIGY Scientific Computing Ctr. |
| Biologist and Systems Analyst |  R-1045.3.16, P.O.Box, Tel:+4161 697-7109 |
| UUCP:...!uunet!mcvax!cernvax!cgch!whbr         CH-4002 Basel, Switzerland |
| Internet:whbr%cgch.uucp@uunet.uu.net; BITNET:whbr%cgch.uucp@cernvax.bitnet|
 ---------------------------------------------------------------------------
                ---The early bird gets caught by the worm---

whbr@cgch.UUCP (Hellmuth Broda) (07/26/89)

Sorry, I messed up because I wanted to catch a train...
In article <849@cgch.UUCP> whbr@cgchd6.UUCP (Hellmuth Broda) writes:
:In article <31495@ccicpg.UUCP> swonk@ccicpg.UUCP (Glen Swonk) writes:
:>I would like to write a large document in pieces,
:>so that each chapter can be compiled/debugged separately.
:>
:>What I would like is a page numbering scheme that the page number
:>would restart at the beginning of each chapter (like it
:>does in some technical manuals).
:>
:>For example:
[...]
:>
:>Any help is appreciated.
:>thanks
:>Glenn L. Swonk		CCI Computers 
:>uunet!ccicpg!swonk
:
:We have been using the following approach:
:
Now here comes the corrected version:
:
\documentstyle{report}
\title{}
\author{}

\begin{document}
\maketitle
\pagenumbering{Roman}% The first pages will be numbered with `normal' Romans
\tableofcontents
\clearpage
% all this is irrellevant to the problem
\addcontentsline{toc}{chapter}{\protect\numberline{}{List of tables}}
\listoftables
\clearpage
\typeout{Starting chapter relative page numbering...}%  
% here comes the relevant part:
\makeatletter%                                        
\def\pagenumbering#1{\global\c@page \@ne%            
   \gdef\thepage{\thechapter -\csname @#1\endcsname \c@page}}% 
\makeatother
\setcounter{page}{1}
\pagenumbering{arabic}% The redefined command takes action
\include{FOO}
\include{BAR}
%...
\appendix
\include{REST}
%...
\end{document}

The included files start like:

\chapter{FOO}
\setcounter{page}{1}% Sorry---this line has to be added to each chapter.
		    % But that ain't much trouble ;-)
:
:------------
:This works with all xrefs, cits etc.  We had to twiggle our local 
:makeindex somewhat to have it digest the new page numbers but that
:was a job on a few awk scripts.
:
Acknowledgement: I want to thank Toni Wuersch <warw@cgch> who helped
		 considerably with the redefinition of \pagenumbering
:
:Hope that helps---Hellmuth Broda
 ___________________________________________________________________________
| Dr.rer.nat. Hellmuth W. Broda |  c/o CIBA-GEIGY Scientific Computing Ctr. |
| Biologist and Systems Analyst |  R-1045.3.16, P.O.Box, Tel:+4161 697-7109 |
| UUCP:...!uunet!mcvax!cernvax!cgch!whbr         CH-4002 Basel, Switzerland |
| Internet:whbr%cgch.uucp@uunet.uu.net; BITNET:whbr%cgch.uucp@cernvax.bitnet|
 ---------------------------------------------------------------------------
                ---The early bird gets caught by the worm---

helen@zen.co.uk (Helen Grayson) (07/31/89)

In article <850@cgch.UUCP> whbr@cgchd6.UUCP (Hellmuth Broda) writes:
>:In article <31495@ccicpg.UUCP> swonk@ccicpg.UUCP (Glen Swonk) writes:
>:>What I would like is a page numbering scheme that the page number
>:>would restart at the beginning of each chapter (like it
>:>does in some technical manuals).
>:
>:We have been using the following approach:

[details of fix deleted]

I have been following the postings on this subject with interest,
as I have recently had to solve the exact same problem.

I took copies of all the suggestions, and eventually found one
(I forget which) that worked.  Thanks to all who contributed.

>The included files start like:
>
>\chapter{FOO}
>\setcounter{page}{1}% Sorry---this line has to be added to each chapter.
>		    % But that ain't much trouble ;-)

If you're using LaTeX and double sided, the end of each included file
has to have \cleardoublepage (if you want each chapter to start on
a right-hand page); or \newpage, to start on the next page.  

So I wrote a little macro which combines resetting the page counter
and clearing the page.  So the main document printing file has
	\include{FOO} \mymacro
	\include{BAR} \mymacro
	etc
and the included file contains only text [and a zillion control sequences!].

>:Hope that helps---Hellmuth Broda

All suggestions gratefully received by novice users.

Helen.

dougcc@csv.viccol.edu.au (Douglas Miller) (08/15/89)

In article <31495@ccicpg.UUCP>, swonk@ccicpg.UUCP (Glen Swonk) writes:
> I would like to write a large document in pieces,
> so that each chapter can be compiled/debugged separately.
>
> What I would like is a page numbering scheme that the page number
> would restart at the beginning of each chapter

> For example:
> 
> 	Chapter1: Intro
> 		pages 1-1 thru 1-10

> Of course, I would like to generate a table of contents
> that reflect the page numbering style.

Below are some fragments from our Operations Manaual style that provide what
you have asked for (you may need to do some reconciliation with your style
file).

Also, roman numeral are used for pages before chapter one (e.g. the
contents pages), and the TeX counters have been reasssigned, so that TeX
reports pages as [0.1] [0.2] ... [1.1] [1.2] [1.3] ... [2.1] [2.2] ... etc.

---------------------------- cut here ---------------------------


\input book.sty

\def\chapter{\@startsection{chapter}{1}{\z@}%
   {-8ex}{3ex}{\huge\bf\centering}}

\def\thechaptertext{}
\def\chaptermark#1{\global\def\thechaptertext{#1}}

\@addtoreset{page}{chapter}  % the page counter will be reset at the
                             % start of each chapter
                            
\def\manualpageheading#1#2#3#4{%
   \hspace{-0.75in}\parbox[t]{7.04in}{\sl
      \rule{0mm}{0mm} #1 \hfill #2\\
      \rule{0mm}{0mm} #3 \hfill #4\vfill}}

\def\manualpage{%
   \stepcounter{page}%
   \ifnum\value{chapter}>0%
      \global\def\thepage{\arabic{chapter}-\arabic{page}}\else
      \global\def\thepage{\roman{page}}\fi
   \manualpageheading{\thetitle}{Page \thepage}{\thechaptertext}{\shortdate}}

\def\manual#1{% 
   \countdef\c@chapter=0 \c@chapter=0 
   \countdef\c@page=1 \c@page=0
   \def\thetitle{#1}%
   \let\@mkboth\markboth
   \def\@oddfoot{}\def\@evenfoot{}%  No feet.
   \def\@evenhead{\manualpage}
   \def\@oddhead{\manualpage}
   \tableofcontents}

-------------------------- cut here ---------------------------------

% Example manual

\documentstyle{manual}

\begin{document}

\manual{Technical Manual}

\include{chapter-one}
\include{chapter-two}
\include{chapter-three}

\end{document}

clarke@hpdtl.HP.COM (Marc Clarke) (09/28/89)

Try the manual style files from the LaTeX server at Clarkson University.  It
supports chapter-page style numbering.