Page Layoutcustom page numbers?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
mtnbkr
Posts: 14
Joined: Wed Dec 24, 2008 1:48 am

custom page numbers?

Post by mtnbkr »

I want to change the page numbering style for a document that I have such that the section number and page number (relative to the current section) are given, e.g., 3-14, would indicate the 14th page in sec. 3 (which maybe the 45th page overall).

I could get this in my footer by customizing the footer with secnum-pagenum, and resetting the page number counter for each section, but the TOC wouldn't be correct. (I'm assuming this as I haven't actually tried it). Anyone out there know how to get the pagenumbers to appear like this in both the footer and the TOC?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
corderin
Posts: 77
Joined: Sun Dec 14, 2008 2:27 pm

Re: custom page numbers?

Post by corderin »

Try with
PREAMBLE
\usepackage{fancyhdr}

DOCUMENT
\pagestyle{fancy}
\fancyfoot[C]{\thesection-\thepage}


but you will have to reset the page counter each section with

\setcounter{page}{1}
mtnbkr
Posts: 14
Joined: Wed Dec 24, 2008 1:48 am

custom page numbers?

Post by mtnbkr »

mtnbkr wrote: Anyone out there know how to get the pagenumbers to appear like this in both the footer and the TOC?
Sorry if I wasn't clear. I can get the footer to show correctly by doing exactly what you have suggested. The problem that I have is the Table of Contents. In the TOC only the page # is shown, so with 17 sections I have 17 different page # 1's. I want the TOC to show the page number to be 1-1, or 17-1 according to which section it is.

Thanks for the reply. Anyone else out there have a suggestion?
corderin
Posts: 77
Joined: Sun Dec 14, 2008 2:27 pm

Re: custom page numbers?

Post by corderin »

Sorry I thought this would change the TOC too, but I have seen it doesn´t...

I have been searching a solution for a while, but....no idea, maybe it would be possible by modifiying a command using the titlesec or titletoc packages, but I have no idea at the moment...I guess the fancyhdr package can´t achieve to solve this problem...
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

custom page numbers?

Post by phi »

Here is a hackish solution:

Code: Select all

\documentclass[english]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{blindtext}
\makeatletter
\@addtoreset{page}{section}
\def\@stpelt#1{\global\csname c@#1\endcsname\expandafter\ifx\csname c@#1\endcsname\c@page\@ne\else\z@\fi}
\def\thepage{\thesection--\@arabic\c@page}
\makeatother
\begin{document}
\tableofcontents
\Blinddocument
\Blinddocument
\end{document}
Note that this is very likely to fail in interesting ways if some other command or package tries to do something to the page numbering. Especially, \pagenumbering will destroy the effect.
A similar hack is

Code: Select all

\makeatletter
\@addtoreset{page}{section}
\def\thepage{\thesection--\number\numexpr\c@page+1\relax}
\makeatother
The chappg package goes some steps further, but works only with chapters.
corderin
Posts: 77
Joined: Sun Dec 14, 2008 2:27 pm

Re: custom page numbers?

Post by corderin »

Interesting...
mtnbkr
Posts: 14
Joined: Wed Dec 24, 2008 1:48 am

Re: custom page numbers?

Post by mtnbkr »

Thanks, that did the it for me. Just what I was looking for.
Post Reply