I'm working in a report that needs the page number relative to the section.







I'm using \numberwithin{page}{section} but two undesirable effects appear:

  1. The pages start from zero: the first page of a chapter is chapternumber.0 , and I'd like them starting from 1.

  2. The separator is a dot, and for legibility I'd prefer a dash

Anybody knows how to do this?

  • The first thing you can do is use \setcounter{page}{1} to force the counter to start at 1 instead of 0. I know how to alter the separator for Figures/Tables (e.g., see subcaption package documentation), so I imagine it's similar for page numbers. Oct 11 '14 at 19:01
  • Okay, so I did some digging and you can use commands like \thechapter, \thesection, and then \leftmark and \rightmark to figure this out. For details, you can check out the following link. Though, I should note that this question should be in the LaTeX forum, not Overflow. Oct 11 '14 at 19:07
  • Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question.
    – Werner
    Nov 6 '14 at 19:23

You need to do at least three things to achieve the output you're after:

  1. Make the page number reset with every use of \section. This can be achieved by


    The above also sets the page number display to be \thesection.\arabic{page} by default.

  2. To correct the above default setting of the page numbering, use

  3. Finally, you want to let the page numbering start from 1. To do this, you need to make sure that the page numbering is adjusted only when you call \section (otherwise it may be reset when calling \subsection, \subsubsection...). Here a patch via etoolbox of \@sect inserts an appropriate page number stepping:

    \patchcmd{\@sect}% <cmd>
      {\protected@edef}% <search>
       \protected@edef}% <replace>
      {}{}% <success><failure>

Here is complete, minimal example that shows the output:

enter image description here

\usepackage[paper=a6paper]{geometry}% Just for this example
\usepackage{lipsum}% Just for this example
\numberwithin{page}{section}% Number page by section
\renewcommand{\thepage}{\thesection-\arabic{page}}% Page numbering style
% Make sure that page starts from 1 with every \section
\patchcmd{\@sect}% <cmd>
  {\protected@edef}% <search>
   \protected@edef}% <replace>
  {}{}% <success><failure>

\section{A section}
\section{Another section}

  • How would one need to modify this solution for koma script classes?
    – FlorianL
    Jul 18 '18 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy