2

I'm using QGIS print layout to create an atlas with around 180 features. I'm trying to find a way to add page number in print layout.

I tried adding text label with [% @atlas_featurenumber %] to show page number, but I have multiple pages for each feature (and they are added dynamically depending on the amount of data in tables), so it does not work well (it shows feature number instead of page number because features have multiple pages).

Is there a direct way to insert page number to print layout?

3

The best I can come up with is

[% @layout_numpages * @atlas_featurenumber + @layout_page - @layout_numpages %]

which seems to work for 2 & 3 page layouts.

Code explanation :

  • @layout_numpages * @atlas_featurenumber : gives the last page number for the feature (e.g. : with 4 pages at the 5th feature, the last page will be 20) ;
  • @layout_page - @layout_numpages : gives the number of pages to subtract (e.g. : with 4 pages, if I'm on the 1st page, I'm 3 pages back from the 4th).
  • 1
    Doesn't this assume that each previous atlas feature has the same number of pages as the current atlas feature? – csk Feb 12 at 21:22
  • it does, but it's possible the @layout_numpages accounts for that - more experiments are needed there – Ian Turton Feb 13 at 8:37
1

When an atlas is set, in a label item, use the following code :

[% @atlas_featurenumber || ' / ' || @atlas_totalfeatures %]
  • That would work if I had one page for each feature, but I have 3 pages per feature. – Marin Leontenko Feb 12 at 14:48
  • Sorry, I've misread. The solution of Ian Turton works. – J. Monticolo Feb 12 at 15:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.