Coloque algo manualmente no cabeçalho da página atual

Coloque algo manualmente no cabeçalho da página atual

É possível escrever algo personalizado no cabeçalho da página atual, por exemplo, como este pseudocódigo

\documentclass{article}

\begin{document}
\thispageheader[R]{My Text}  %Displays only this in the header
\newpage
\thispageheader[R]{Another Text} %Displays only this in the header
\newpage 
\thispageheader[L]{Just another Text on the left} %Displays only this in the header
\end{document}

É importante para mim que tudo seja feito localmente. Não quero definir diferentes estilos de cabeçalho sofisticados globalmente para cada texto de cabeçalho manual.

Responder1

Contanto que você esteja disposto a definir as páginas de um grupo, é relativamente fácil

\documentclass{article}

\usepackage{fancyhdr}
\usepackage{lipsum}

\lhead{\headerL}
\chead{\headerC}
\rhead{\headerR}
\def\headerL{}
\def\headerC{}
\def\headerR{}
\newcommand{\thispageheader}[2][R]{\expandafter\def\csname header#1\endcsname{#2}}

\pagestyle{fancy}
\begin{document}

{\thispageheader[R]{My Text}  %Displays only this in the header
\lipsum[1]
\newpage}
{\thispageheader[R]{Another Text} %Displays only this in the header
\lipsum[1]
\newpage}
{\thispageheader[L]{Just another Text on the left} %Displays only this in the header
\lipsum[1]\newpage}
\end{document}

Não está muito claro como você deseja que os cabeçalhos se comportem fora dos grupos. Talvez algo como

\newcommand{\resetheaders}{\def\headerL{}\def\headerC{}\def\headerR{}}

informação relacionada