The key to the solution is adequate styling which your sample does not meet. You have direct formatting which promotes visual appearance while your problem calls for semantic markup, i.e. a style flags a semantic usage allowing to make a distinction between similarly looking sequences.
I started by breaking your glossary entries into two paragraphs so that the significance of each can be properly advertised: the term itself (from which I removed the “bold” direct formatting) as Heading 10 and the explanation as Definizione. Note that I didn’t remove the various direct formatting from the explanation, generally italics which have two purposes: emphasis on a new word or cross-reference to another entry. These are two different semantic values and should receive two different character styles (one being possibly built-in Emphasis).
I played with the Text Flow
parameters of both styles (Keep with next paragraph and widow/orphan controls) so that a term is never separated from its explanation by a page break.
I used Heading 10 because it is available but you can use a user paragraph style attached to some outline level. Remember you can limit the depth of the TOC so that level 10 is not collected.
I then enabled the header in the various page styles of the glossary. Since you use built-in Left Page and Right Page, it is likely they are also used in other chapters than the glossary. As the header contents is specific to the glossary, You should also use specific user page styles in your glossary so that the chapters don’t show glossary headers (which anyway would be wrong because the chapters have not been prepared for the specific information). I let you do that.
We’re now ready to add data into header and footer.
Glossary-variant A.odt (18.7 KB), the simplest but not conforming to your specification
In the header, Insert
>Field
>More Fields
, Document
tab, Type Chapter, Format Chapter Name, Level 10 (corresponding to Heading 10). Writer captures the state of the first paragraph in the page and uses this information to insert the requested chapter heading.
Note it does not work on the first page because the first paragraph is a Heading 2 and although the request is for level 10, this level 10 does not exist at this position and level 2 is reported. More on that later.
In the footer, the same field is inserted to capture the state in the last paragraph. There is no problem here.
I noticed you also applied direct formatting in your footer. Don’t do that, Footer paragraph style default configuration is versatile enough to not need any direct formatting.
Glossary-variant B.odt (19.0 KB) where first and last entry are both in the header
As mentioned, Writer determines the outline state either at start of page or at end of page. There is no way to tell it to forward scan the page to retrieve the state and anyway the fields will report only the current state (you can’t request some other state than the current one). Consequently, what is known in the footer should be sent “visually” or "apparently into the header despite the fact that the data is generated in the footer. This is possible with a frame. The frame will get its information from its anchor but will be moved into the header.
I create a dedicated frame style names Last entry for the purpose. It is anchored To paragraph in the footer but moved upwards through its Position parameters. I chose the Page text area reference. It makes it easy to position the frame at right of header. Vertical position is a bit more tricky and you’ll have to adjust it it you change your header geometry in the page style. For ease of formatting I used Header paragraph style inside the frame so that contents will also be updated in case you change Header.
Glossary-variant C.odt (19.1 KB) addressing the issue of the first page
As mentioned earlier, the initial outline state is determined from the first paragraph in the page. Your glossary starts with its Heading 2. Consequently, what is captured is levels 1 & 2 and nothing else because at this point there is no deeper level. The solution is to force beginning of the glossary on a new page with a manual page break in the first entry. This means the glossary heading is left alone on its page. You could then format it in the center of the page like we see in some books where part (subdivision/volume) heading has a specific. layout different from chapter. I let you do that.
Side remark: you forced First Page built-in page style at start of your glossary (and I assume you did the same in your other chapters). This is not the intended usage of this style. As the name implies (badly), it is the very first page of the book, the cover page. You could have a simpler solution by unticking the check boxes in the Header
and Footer
tabs of the chapter and glossary page styles.