First, let’s clear a vocabulary problem. I assume that your “sections” are the main first-level subdivisions of your document and contain then “chapters” as a second-level hierarchy. With this ordering, section heading are “naturally” styled Heading 1 and chapters Heading 2.
The styles are applied to the relevant paragraphs in the text flow.
In the header, you Insert
>Fields
>Other
, tab Document
, choosing Type Chapter, Format either Chapter name or another one if you want the number also displayed. Check that Level is 1 to reference the current Heading 1 title.
In the footer, you insert a similar field, but you set Level to 2 to reference the current Heading 2.
But, the captured Heading x is the one active at time of the capture. Said otherwise, you have no problem in the header because the first Heading 1 in the page is used. However, in the footer, you display the last Heading 2 of the page, which may confuse the reader if you have a change in the middle of the page.
Note: when you write
But I can’t put heading 2 into the footer
I hope you did not style the text in the footer as Heading 2 . This will never work.
EDIT 2018-03-23
You define your new “sections” with a Heading 1 paragraph. You enabled the Hidden attribute in the style to make it invisible.
As far as I know, the Hidden attribute is meant to remove completely the flagged paragraphs as if they were never inserted. This allows to print several versions of the same document simply by adjusting the attribute. In academics, thinks for instance of the teacher and student books.
Here you attempt a border line usage. I am surprised that it half works, but that may be a side effect of Heading x special properties.
Heading 1: despite being hidden, the heading is entered into the known list of headings but all other effects are disabled as expected (for instance, I added a page break to force your “section” on a new page but it did not work because paragraph is hidden).
Heading 2: bears the page break to right page to force your “chapters” to begin on a new page and, also, enters the heading in the known list.
However, with this scheme, I see two pitfalls.
-
Since your Heading 1 is hidden, your section does not start systematically on a new page. This is what happens in the last page of your “section” 1. The Heading 1 for “section” 2 is part of this page, so that when we reach the footer, this Heading 1 is now the current one. We’re already in “section” 2 while you intend it be effective only after the Heading 2 for the new “chapter”. Keep with next paragraph could have solved the issue, but it has no effect since the paragraph is hidden and, nevertheless, it is overridden by the page break in Heading 2.
I experimented with a page break to fix the issue but since Heading 1 is hidden, it does nothing.
-
If you start your new “section” with an introductory text not preceded by a Heading 2, this introduction appears sequentially in the same page as the last paragraphs of the previous “section”. Moreover, in this configuration, the reference to the latest level-2 heading seems to pick up the latest in the previous “section” instead of being reset.
Suggested fix
“Sections” in a book are significant. Instead of hiding “section” change, make them explicit wit a visible (= not Hidden) Heading 1 paragraph. Since it is an important break in the book, use a page break in the style definition and adjust “before” vertical spacing so that it is approximately centered in the page. You may also center the heading between its margins. Your Heading 2 already forces a page break, so you don’t need to bother with “below” vertical spacing, unless you care for an introductory text.
To avoid unelegant look, use a simple page style without header nor footer (or limited to page number) so that the “section” title is not repeated. You can eventually set a Next page style in the Organizer
tab so that you automatically switch to your common page style, should you add text after the “section” heading.
There remains a small glitch. If your introductory text (not preceded by a Heading 2) spills over to next page, the level-2 heading reference does not exist and the field will revert to level-1 instead of being blank.
Please give feedback in comments.
If this answer helped you, please accept it by clicking the check mark to the left and, karma permitting, upvote it. If this resolves your problem, close the question, that will help other people with the same question.