Forum How do I...?

Custom chapter page counter and nth(n)

Anders Bille
I have a use-case where i want to split the document up in named pages as chapters and where i need a custom counter to count pages from the beginning of a chapter (not the beginning of the entire document) so I can access a chapter page with nth(custom counter).

I am trying to target page 2 of chapter 1 and insert content in a margin-box no matter if the number of chapters or chapter pages expand.

Right now the chapter-1-counter always shows “1”:

#chapter-1 {
page: chapter-1;
counter-increment: chapter-1-counter;
}

@page chapter-1:nth(2) {
@bottom-right{
content: counter(chapter-1-counter);
}
}

Is this possible or should there be used some workaround?
mikeday
You will need to apply "prince-page-group: start" to #chapter-1 for :nth(2) to match. However, it is not possible to increment custom counters for each page yet, so the numbering is not possible unless you use the regular page counter and a JavaScript function to subtract the offset. It's a bit tricky.
Anders Bille
Works perfect, thanks! my main concern was to get nth(n) on chapter pages to work and the "prince-page-group: start" solved this.