1

In my MNWE I try to change style for section in two column scrbook document. In same time I want to have page header also on pages where the first text line is the section header.

In my code I am loosing the setting of the page header because the section behaves in same manner like chapter. If the page contains only paragraphs it works as I want.

I try to use \AddtoDoHook technique but without success (therefore it is commented in MNWE).

MNWE:

% https://tex.stackexchange.com/questions/662860/komascript-section-header-over-two-column-text-layout
\documentclass[a4paper,11pt,twocolumn, chapterprefix=on]{scrbook}
\usepackage{blindtext}
\usepackage{lipsum}
\usepackage{xcolor} 
\usepackage[headsepline, automark]{scrlayer-scrpage}   
\usepackage{currfile}

\pagestyle{scrheadings}
\setkomafont{pageheadfoot}{\normalfont\normalcolor\itshape\small} \setkomafont{pagenumber}{\normalfont\bfseries} \chead{\currfilename}
% https://tex.stackexchange.com/questions/114570/koma-script-scrpage2-footer-height \ihead{\pagemark} % scrguien page 255 \ofoot[]{} % remove pagenumber from outer foot \cfoot[]{} % remove pagenumber from centre foot

% \AddtoDoHook appends persistent code to the hook named name. % @gobble: https://tex.stackexchange.com/questions/85796/why-does-gobble-take-one-argument \RedeclareSectionCommand[style=chapter]{section} \makeatletter \AddtoDoHook{heading/begingroup/section}{\KOMAoptions{chapterprefix=false}@gobble} % \AddtoDoHook{heading/begingroup/section}{\pagestyle{scrheadings}@gobble} % \AddtoDoHook{heading/begingroup/section}{\ihead{\pagemark} @gobble} % \chapterlinesformat{level}{number}{text} \renewcommand{\chapterlinesformat}[3]{% @tempswafalse % \Ifstr{string 1}{string 2}{then code}{else code} page 346 scrguide-en 3.38 \Ifstr{#1}{section}{% \color{white} \colorbox{black}{% \parbox{\dimexpr\linewidth-2\fboxrule-2\fboxsep}{% \raggedsection @hangfrom{#2}{#3}% }% }% ]% }{% @hangfrom{#2}{#3}% }% } \makeatother

JardaFait
  • 3,922

2 Answers2

2

If style=chapter or style=part is used in the optional argument of \RedeclareSectionCommand the key pagestyle and macro \<name>pagestyle are provided. The key pagestyle sets the page style for pages with the heading. By default, the value of key pagestyle is plain. The macro \<name>pagestyle is used to store the value of key pagestyle.

So you can use either

\RedeclareSectionCommand[style=chapter,pagestyle=scrheadings]{section}

or

\RedeclareSectionCommand[style=chapter]{section}
\renewcommand*{\sectionpagestyle}{scrheadings}

to get the desired result.

First example:

% https://tex.stackexchange.com/questions/662860/komascript-section-header-over-two-column-text-layout
\documentclass[a4paper,11pt,twocolumn, chapterprefix=on]{scrbook}
\usepackage{blindtext}
\usepackage{lipsum}
\usepackage{xcolor} 
\usepackage[headsepline, automark]{scrlayer-scrpage}% <- sets page style scrheadings automatically
\usepackage{currfile}

\setkomafont{pageheadfoot}{\normalfont\normalcolor\itshape\small} \setkomafont{pagenumber}{\normalfont\bfseries} \chead{\currfilename} \ihead{\pagemark} \ofoot{} \cfoot{}

% \AddtoDoHook appends persistent code to the hook named name. % @gobble: https://tex.stackexchange.com/questions/85796/why-does-gobble-take-one-argument \RedeclareSectionCommand[style=chapter,pagestyle=scrheadings]{section}% <- changed \makeatletter \AddtoDoHook{heading/begingroup/section}{\KOMAoptions{chapterprefix=false}@gobble} \renewcommand{\chapterlinesformat}[3]{% @tempswafalse \Ifstr{#1}{section}{% \color{white} \colorbox{black}{% \parbox{\dimexpr\linewidth-2\fboxrule-2\fboxsep}{% \raggedsection @hangfrom{#2}{#3}% }% }% ]% }{% @hangfrom{#2}{#3}% }% } \makeatother \usepackage{blindtext} \begin{document} \blinddocument \end{document}

Second example:

% https://tex.stackexchange.com/questions/662860/komascript-section-header-over-two-column-text-layout
\documentclass[a4paper,11pt,twocolumn, chapterprefix=on]{scrbook}
\usepackage{blindtext}
\usepackage{lipsum}
\usepackage{xcolor} 
\usepackage[headsepline, automark]{scrlayer-scrpage}% <- sets page style scrheadings automatically
\usepackage{currfile}

\setkomafont{pageheadfoot}{\normalfont\normalcolor\itshape\small} \setkomafont{pagenumber}{\normalfont\bfseries} \chead{\currfilename} \ihead{\pagemark} \ofoot{} \cfoot{}

% \AddtoDoHook appends persistent code to the hook named name. % @gobble: https://tex.stackexchange.com/questions/85796/why-does-gobble-take-one-argument \RedeclareSectionCommand[style=chapter]{section} \renewcommand*{\sectionpagestyle}{scrheadings}% <- added \makeatletter \AddtoDoHook{heading/begingroup/section}{\KOMAoptions{chapterprefix=false}@gobble} \renewcommand{\chapterlinesformat}[3]{% @tempswafalse \Ifstr{#1}{section}{% \color{white} \colorbox{black}{% \parbox{\dimexpr\linewidth-2\fboxrule-2\fboxsep}{% \raggedsection @hangfrom{#2}{#3}% }% }% ]% }{% @hangfrom{#2}{#3}% }% } \makeatother \usepackage{blindtext} \begin{document} \blinddocument \end{document}

dexteritas
  • 9,161
esdd
  • 85,675
1

The solution is simple. Instead of

\RedeclareSectionCommand[style=chapter]{section}

use the modification

\RedeclareSectionCommand[style=chapter,pagestyle=scrheadings]{section}

as it was suggested in comment.

JardaFait
  • 3,922