Hi Marco,
First of all lots of thanks for your interest in this problem.
However, EVERY solution that was proposed either by
you or me has one problem.
It does not distinguish between first heading 2 and appropriate
heading 1. E.g.
Yes, and that will keep being a problem if you allow Word to search downwards
(because it doesn't find a heading further up).
That's the reason I introduced the hidden Heading 2 at the start -- probably
best in a throwaway "Chapter 0". Though you are right that you'd need to delete
that manually from the TOC.
So I still think this is most elegant solution and uses only documented
switches (it works at least if you have less than 10 headers 1):
{IF "{STYLEREF 1 \n}.2"<{STYLEREF 2 \h} {STYLEREF 1 \n} {IF {STYLEREF 1
\n}>{STYLEREF 2 \n} {STYLEREF 1 \n} {STYLEREF 2 \n} }
Should that be an \n instead of a \h? And you should keep aware that the number
of "Heading 2" subchapters in a chapter should be less than 10 for the first
"IF".
Before this thread I wasn't thinking much about how the chapter numbers are
compared.
With "1, 1.1, 1.2, 2 ...", they are compared as decimals (if a dot is your
decimal separator), or as strings (if it isn't).
With "1., 1.1., 1.2., 2., ..." legal numbering, they are compared as dates.
Neither of these is really right for comparing chapter numbers, and it may mean
you and I are getting different results in some cases.
The first IF checks if header 1 is smaller than first part of header 2
(no problem with commas). If so, simply put header 1. Otherwise use
standard STYLEREF formula.
It doesn't work for me 100%:
If you have some subchapters further down, say "4.3", "4.4", ... "4.12", then
the expression
IF "{STYLEREF 1 \n}.2"<{STYLEREF 2 \n} will be true (4.2 < 4.3 ...), and you get
"Heading 1" instead of "Heading 2".
You could minimize that problem by using ".9" instead of ".2".
However, it has the above mentioned problem, which - it seems - cannot
be solved. There is no code field which would tell if you are dealing
with page containing 2.1 or 2.
As long as Word is allowed to search downwards, that seems to be true.
Regards,
Klaus