Forum How do I...?

How do I select specific pages for changebars with page groups?

We use Prince to publish long textbooks that have a couple of page groups (frontmatter and chapter) and multiple instances of those groups (many chapters). We are trying to implement changebars in a new way but we are having a hard time targeting individual pages because our page groups restart multiple times throughout the book.

We’ve been using this resource:

  • Can we use the nth page selector to target an absolute page regardless of page groups?
  • Are we using the nth selector incorrectly?

This is the CSS that is causing our changebars to be duplicated across every nth page of a chapter:

@page:nth(1) { @left { content: flow(bars1) } }
@page:nth(2) { @left { content: flow(bars2) } }

This is how we’re using page groups:
chapter {
	  page: chapter;
	  page-break-before: right;
	  prince-page-group: start;

@page chapter {
  margin: 0;
  margin-bottom: 0.5in;
  margin-top: 0.875in;

@page chapter:first {
  margin-top: 0;
  @top {
    content: none;
  @top-left {
    content: none;
  @top-right {
    content: none;
  @bottom-right {
    content: none;
At the moment the :nth() selector is applying to the page number within the current page group, which is convenient for some things but a little confusing in this situation. We may need to revise how it works, or introduce an alternative mechanism.
Thank you for the quick response. Do you have any ideas for how we might get around this? We could generate or automate any of the stages, but we'd like to limit the changes to the actual DocBook markup to avoid breaking existing CSS selectors.
The only solution I can think of is quite unpleasant and involves generating a unique page group name for each chapter so they can be distinguished later, eg. @page chapter3:nth(7).

It would be easier if we added an alternative page selector mechanism.
@mikeday any updates on this?
Using v12.5, I've been running into the same problem myself, where it's extremely difficult to target a page uniquely. I assumed from the way that the rest of page rules worked that to target the nth page of each chapter, I would do something like:
@page chapter:nth(n)

but that

would target the nth page of the pdf, period. But this seems not to be the case - as it is acting more like how you would expect something like
@page *:nth(n) 
to work, if such grammar was acceptable.
We don't have a new mechanism for this yet, I think it will still require some intensive scripting to get it to work.