# Issue with chapter numbers in page numbers

I am writing my thesis and using a template given by my university. To get the chapter numbers in the page number, I use the following commands:

\@addtoreset{page}{chapter}
\renewcommand{\thepage}{\thechapter-\arabic{page}}


Chapter heading formating is done by using the titlesec package. So to get new chapters in an odd page I use:

\newcommand{\chapterbreak}{\cleardoublepage}


However, the issue with this is that the last page of each chapter gets numbered with the chapter number of the next chapter. For eg. the last page of chapter 2 will be numbered 3-0 instead of 2-10.

The way I see it, the chapter number is being incremented before the chapter break is done. Any ideas how to fix this or work around this?

Update 1: I have also tried the chappg package which has the same problem.
Update 2: Minimum working example:

\documentclass[twoside]{report}
\usepackage{titlesec}
\usepackage{lipsum}\setlipsumdefault{1-3}

\titleclass{\chapter}{straight}
\newcommand{\chapterbreak}{\cleardoublepage}

\makeatletter
\renewcommand{\thepage}{\thechapter-\arabic{page}}
\makeatother

\begin{document}
\chapter{One}
\lipsum
\chapter{Two}
\lipsum
\chapter{Three}
\lipsum
\end{document}


\cleardoublepage doesn't seem to work for some reason in my example, but the problem with the page numbering holds.

-
Welcome to TeX.SX Try please to provide a Minimal working example so that we know exactly what your issue is and we can help you by modifying your code. –  yo' Jan 24 '12 at 9:41
After a bit of googling I found a chappg package which does exactly what you need. –  yo' Jan 24 '12 at 9:52
The chappg package has the same issue. –  Adi Jan 24 '12 at 10:09
It's very difficult to see what's going wrong without seeing the code your are using. Please add a MWE which produces the error. –  Martin Scharrer Jan 24 '12 at 10:21
@Adi: Would you mind having the empty page completely empty, i.e. without any heders or footers or so? In that case, there's a hint in the manual for fancyhdr package, Section 15 –  yo' Jan 24 '12 at 10:33

The main problem is that \refstepcounter{chapter}, which is issued by \chapter, will set the page counter to 0, instead of the required 1. Page numbers are stepped when the page is completed and shipped out, so the counter must start from 1.

You have to do some adjustments

\documentclass[twoside]{report}
\usepackage{titlesec}
\usepackage{lipsum,etoolbox}

\titleclass{\chapter}{straight}

\makeatletter
\makeatother
\renewcommand{\thepage}{\thechapter-\number\numexpr\arabic{page}+1\relax}
\patchcmd{\cleardoublepage}{\ifodd}{\unless\ifodd}{}{}
\preto\chapter{\cleardoublepage}
\AtBeginDocument{\setcounter{page}{0}}

\begin{document}
\chapter{One}
\lipsum
\chapter{Two}
\lipsum
\chapter{Three}
\lipsum
\end{document}


We want to issue \cleardoublepage just before \chapter, so we prepend the code to the code for \chapter (\chapterbreak is issued at the wrong time). We need also to patch \cleardoublepage to reverse the \ifodd test and, finally, to set the start of the page counter to 0.

The page number shown in the log file will be off by one, but the printed number will be correct.

-
Your solution worked. Thanks a lot. –  Adi Jan 24 '12 at 13:24