[texhax] Insert chapter and section heading into document header

Schwartz, Steven J s.schwartz at imperial.ac.uk
Sat Dec 15 20:25:14 CET 2012


Jerry,

Jerry wrote on 2012-12-15:
----------------

> %I am attempting to use this to get the headers correct/=
> \fancyhead{r}{\chaptertitlename\ \thechapter\ \thesection \thesubsection}
> 
> The problem is that it does not stay in sync with the document. In
> fact the first page has:
> 
> "Article II 1.1.C" when it should be "Article I 1"
> 
> I would really appreciate any assistance that someone might be able to
> afford me.

I'll keep this short as others on the list will be more proficient, but I think you'll need to get the information you need into the appropriate \leftmark or \rightmark commands. Although it's a bit confusing, read section 9 of the fancyhdr documentation, noting in particular:

"The \leftmark contains the Left argument of the Last \markboth on the page, the \rightmark
contains the Right argument of the fiRst \markboth or the only argument of the fiRst \markright
on the page."

This is designed to be clever in twosided printing, for example, and to show on a spread the information corresponding to the beginning on the left page and the end on the right page (I think). The rest of that section of the documentation shows how to re-define, e.g., \sectionmark (which is called when you issue a \section command) to put the information you want, and format it as you want, into \markboth or \markright. I'll stop here as I've hit the limit of my ignorance, but suggest you play with these and replace your 

\fancyhead{r}{\chaptertitlename\ \thechapter\ \thesection \thesubsection}

with something like

\fancyhead{r}{\rightmark}

In essence, your problem stems from the fact that the output from things like \thechapter depends on WHEN in your latex run that command is executed and the header put together by latex. 

HTH
Steve
--------------------------------------------------------------------
Professor Steven J Schwartz        Phone:  +44 (0)207 594 7660
Head, Space & Atmospheric Physics  Fax:    +44 (0)207 594 7772
The Blackett Laboratory            Email:  s.schwartz at imperial.ac.uk
Imperial College London            Office: Huxley 6M67A
London SW7 2AZ, UK                 Web:    www.sp.ph.ic.ac.uk/~sjs
--------------------------------------------------------------------





More information about the texhax mailing list