TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
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
up vote 4 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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