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.

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}
\titleformat{\chapter}[hang]{\bfseries\huge}{\thechapter\quad}{0em}{}
\newcommand{\chapterbreak}{\cleardoublepage}

\makeatletter
\@addtoreset{page}{chapter}
\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.

share|improve this question
2  
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. –  tohecz Jan 24 '12 at 9:41
    
After a bit of googling I found a chappg package which does exactly what you need. –  tohecz Jan 24 '12 at 9:52
    
The chappg package has the same issue. –  Adi Jan 24 '12 at 10:09
1  
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
1  
@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 –  tohecz Jan 24 '12 at 10:33
show 1 more comment

1 Answer 1

up vote 4 down vote accepted

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}
\titleformat{\chapter}[hang]{\bfseries\huge}{\thechapter\quad}{0em}{}

\makeatletter
\@addtoreset{page}{chapter}
\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.

share|improve this answer
    
Your solution worked. Thanks a lot. –  Adi Jan 24 '12 at 13:24
add comment

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.