[Tex/LaTex] Custom text in header

fancyhdrheader-footer

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?

Best Answer

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).