0

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 Aug 4 '17 at 22:27
  • It would change every time setheaderdata is called. It can be any text. – Mlha Aug 4 '17 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 Aug 4 '17 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 Aug 5 '17 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 – Mlha Aug 5 '17 at 8:35
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:

\newcommand{\headerdatafirst}{}
\newcommand{\headerdatasecond}{}
\newcommand{\headerdatathird}{}

\newshortmark\headerdatafirst
\newshortmark\headerdatasecond
\newshortmark\headerdatathird

\newpagestyle{datastyle}{
    \sethead{\headerdatafirst}{\headerdatasecond}{\headerdatathird}
}

\newcommand{\setheaderdata}[3]{
    \renewcommand{\headerdatafirst}{#1}
    \preshortmark\headerdatafirst
    \renewcommand{\headerdatasecond}{#2}
    \preshortmark\headerdatasecond
    \renewcommand{\headerdatathird}{#3}
    \preshortmark\headerdatathird
}

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

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.