I am using fancyhdr and want to have custom text in the header which changes every few pages. Currently I am using the trick with markboth - I have a function \newcommand{\setheaderdata}[2]{\markboth{#1}{#2}} and then display these data with \fancypagestyle{mystyle}{\ \fancyhead[C]{\leftmark} \fancyfoot[LO]{\rightmark} } The trouble is, now I want to add a third text to the header and since there is no centermark, I have no way of getting it into the header.

I have tried making a custom command which I redefine every time I want to change the header text, but for some reason, the headers ignore this redefinition...

So, how do I get custom text (which changes throughout the document) into the header?

  • How would it change? According to which rules?
    – Bernard
    Commented Aug 4, 2017 at 22:27
  • It would change every time setheaderdata is called. It can be any text. Commented Aug 4, 2017 at 22:41
  • Could you post a minimal example code with some of these header data? I'm not sure I fully understand, but Id think it might be easier with titleps.
    – Bernard
    Commented Aug 4, 2017 at 22:48
  • the marks are to be set by chapter and section headings. If you want to put any text you want to the headers and footers, do: \fancyhead[LE,RO]{Wombat}\fancyhead[LO,RE]{Capybara}\fancyhead[CE]{Mara}\fancyhead[CO]{Mlha}
    – Johannes_B
    Commented Aug 5, 2017 at 5:54
  • The problem is, I don't know whether i want to put Wombat or Capybara in the heading, because the contents of the document are generated with a Lua script Commented Aug 5, 2017 at 8:35

1 Answer 1


Unfortunatelly, I couldn't find any solution using the fancyhdr package and as far as I know, pagestyles cannot be renewed. But (thanks to Bernard) I found a solution using the titleps package:





Now every time setheaderdata is called, the pagestyle datastyle will contain the parameters in the header (until setheaderdata is called again).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .