0

Here is what I would like to achieve: I would like to be able to set the header content for individual pages at the start of the respective pages in the source code.

My thinking was to place the content in a variable \@thisheader that is put into the header and switch \thispagestyle to display it on that page only.

In the MWE, this works with the defined macro \thisheadermacro. However, since I wish to put a list into the header, I would prefer defining a new environment. And this is where I am stuck.

Using the environ package, I can get the code to compile, but the \@thisheader is not changed globally, and hence the previous header content is shown. Replacing \def with \gdef or \xdef did not help. And entirely replacing the variable definition by calling \chead{} directly did not do it either.

Defining a \newenvironment (see below) throws errors, probably because of grouping issues, which I cannot fix.

Is there a way to use my \NewEnviron approach? Or is there maybe a different, more elegant solution?

\documentclass{scrbook}

\usepackage{showframe, blindtext}

\usepackage{scrlayer-scrpage}
\pagestyle{plain}
\clearpairofpagestyles
    \chead{\@thisheader}

\newcommand{\thisheadermacro}[1]{%
    \def\@thisheader{\begin{itemize} #1 \end{itemize}}
    \thispagestyle{headings}}

\newenvironment{thisheaderenvironment}{%
    \def\@thisheader\begingroup\begin{itemize}}{%
    \end{itemize}\endgroup
    \thispagestyle{headings}}

\usepackage{environ}
\NewEnviron{thisheaderEnviron}{%
    \def\@thisheader{\begin{itemize} \BODY \end{itemize}}
    \thispagestyle{headings}}


\begin{document}

\thisheadermacro{\item thisheadermacro}
\blindtext

%% The errors for this block, I cannot fix at all.
%\clearpage
%\begin{thisheaderenvironment}
%thisheaderenvironment
%\end{thisheaderenvironment}
%\blindtext

%% This block compiles, but does not yield the right header.
\clearpage
\begin{thisheaderEnviron}
\item thisheaderEnviron
\end{thisheaderEnviron}
\blindtext

\end{document}

PS. I have also looked into using the background package. But here I run into the same problem: Using \backgroundsetup inside a group has no global effect.

2

It's not clear why you want to use itemize, but here it is:

\documentclass{scrbook}
\usepackage{environ}

\usepackage{showframe, blindtext}

\usepackage{scrlayer-scrpage}
\pagestyle{plain}
\clearpairofpagestyles
\makeatletter
\chead{\@thisheader}

\NewEnviron{thisheaderEnviron}{%
  \xdef\@thisheader{%
    \noexpand\begin{itemize}
    \unexpanded\expandafter{\BODY}
    \noexpand\end{itemize}}%
  \thispagestyle{headings}
}
\makeatother

\setlength{\headheight}{60pt}

\begin{document}

\begin{thisheaderEnviron}
\item First
\end{thisheaderEnviron}
\blindtext
\clearpage

\begin{thisheaderEnviron}
\item Second
\end{thisheaderEnviron}
\blindtext

\end{document}

enter image description here

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.