2

I want to create a TeX document with sections and a running header containing the name of the current section. I know I can use \mark{} to mark the section headings and then use \topmark or \firstmark to show the section name in my header. The problem is that neither \topmark nor \firstmark do what I want (they're actually more suitable for typesetting dictionaries).

I would like the header to reflect the section the contents of which appear at the very top of the current page. In other words, I want to use mostly \topmark, but when a new section begins on the current page before any other text before it, I want to use \firstmark (or, alternatively, leave the header blank), because then \topmark refers to the previous section and thus is irrelevant. Any ideas on how I could do that?

  • 3
    There's exactly this problem explained in the TeXbook, since TAOCP uses that kind of headers. The trick consists in issuing \mark twice, before and after the section title, if I remember correctly. – egreg Jun 28 '11 at 16:58
  • On page 260, to be precise. – Javier Bezos Jun 29 '11 at 14:12
  • @egreg Thanks, that helped. But there's one problem: on the first page, \topmark is still empty. Can I tell TeX to use \firstmark instead? – ondra.cifka Jun 29 '11 at 17:27
  • 2
    Usually the first page has no headers. :) I suppose that \ifnum\pageno=1 \firstmark\else\topmark\fi can solve the issue. – egreg Jun 29 '11 at 18:04
4

Usually the first page in a document has no header; if it's needed for some special application, one can say

\ifnum\pageno=1 \firstmark\else\topmark\fi

in the code for producing the header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.