To count number of landscape pages and then resume the sequence of "Left" and "Right" pages from the correct style

I have a document that contains both portrait-oriented and landscape-oriented pages. The portrait-oriented pages are styled as spreads: that is, I use “Right Page” and “Left Page” styles for them.

“Right Page” and “Left Page” pages are applied by Writer one after another automatically, there are no problems. Then I manually insert few pages with “Landscape” style. And then I need to resume the sequence of portrait-oriented pages. And this is where I have a problem. I need to manually specify whether the sequence of portrait-oriented pages should be restored from the left page or from the right page. And this is boring and error-prone to count; instead, I would Writer to do this job for me. That is, to count the number of landscape pages and then restore the sequence of portrait-oriented pages from the correct page style (that is, from the left or from the right style, depending of the number of landscape pages).

Is there a macro for it? Or another workaround?

Actually, I think, there is no need to count the number of landscape pages at all. It is only required to check whether the page number is odd or even.

And you have the status bar turned on and can see what page number the cursor is on?

See also:
https://wiki.documentfoundation.org/Videos/User_interface#Status_bar

Yes. [ Some dummy text. The comment cannot be less than 10 characters ]

Which page does the status bar show when you put the cursor in the last landscape page?
Is that sufficient information for you?

You have a built-in way of achieving your effect. It relies on an option of page styles.

Left Page and Right Page are specialised on a side and therefore will create a blank page if you force restart with the “wrong” page style".

Instead, create your own page style for your portrait pages with page layout Right and Left. In Header (and/or Footer) tab, enable the header (resp. footer) and untick Same content on left and right page.

When you switch back to your page style, Writer will automatically choose the correct “side” of the page style. Without macro, this is more resilient to edits because the macro does not need to be rerun when pagination changes.

There remains the case when you require the first page of a chapter to start usually on a right page. This can be handled with a dedicated page style which is linked to your portrait page style: when the end of the first page is reached, LO switches to your alternating portrait page without manual action on your part.

1 Like

Thanks, this seems to be a good solution. However, it seems to be better to use mirrored layout so that I can have different margins for left and right pages.

This is one of the extra possibilities. If you’re under 7.2.x, a new parameter has been added to page styles: gutter width to add some space on the inner edge of the sheet added to the margin. This is strictly equivalent to defining non-symmetric margins except Writer makes the math for you.