It seems the StyleRef
field gets you close, but might not be what you want if the heading you're referring to also occurs somewhere on the current page:
StyleRef field location
Where you insert the StyleRef field determines the direction that Word searches for the style and thus can affect which text is inserted.
When you insert the field in:
[...]
Headers and footers (results for printed document): Word searches the current page, from top to bottom, for the specified style. If the style isn't found, Word searches next from the top of the page to the beginning of the document, and then from the bottom of the page to the end of the document. If the
\l
switch is used, Word searches from the bottom of the page to the beginning and then to the end of the document.
I feel this would be fine to refer to Heading 1 if that heading always starts on a new page (in which case I'm sure you don't want the previous Heading 1 to show on top).
It also seems to adhere to your "If the page has Section 1.2.1 in it, then the header should say The Title > Some Other Heading > A Subheading
". But I'd expect A Subheading
to also show if it started on a previous page and was still continuing on top of the current page. For that, with StyleRef
, you'd get Another Subheading
if that starts somewhere on the current page; just like you asked for, but it might be confusing.
Also, things might be really wrong if some Heading 1 is found on the current page, but its child Heading 2 is not, in which case Word tries to find a Heading 2 on previous pages. And if parts do not use all levels of headings, then headings from different parts might be found and be combined in the breadcrumb, and Word might even be looking forward to find a match.
Consider these bad results:
------------------------------------------------------ page 1: Title 1 > The 1.1 Heading > A 1.2.1 Subheading 1. Title 1 Lorem ipsum dolor ... ------------------------------------------------------ page 2: Title 1 > The 1.1 Heading > A 1.2.1 Subheading 1.1 The 1.1 Heading 1.2 The 1.2 Heading 1.2.1 A 1.2.1 Subheading Lorem ipsum dolor ... 1.2.2 A 1.2.2 Subheading Lorem ipsum dolor ... ------------------------------------------------------ page 3: Title 2 > The 1.3 Heading > A 1.2.3 Subheading ... sit amet, consectetur adipiscing ... 1.2.3 A 1.2.3 Subheading ... 1.3 The 1.3 Heading ... 2. Title 2 2.1 The 2.1 Heading ...
So, the success of StyleRef
depends on the actual structure of your document. I hope there's a better way, which also takes the actual hierarchy of headings into account (maybe something related to a table of contents), rather than just inserting references to possibly unrelated headings...