0

Typing a document with package titlesec, pagestyles can easily mark first and last section title in the page header. But How to display all section marks that appears in the page to the page's header? TKS!

HERE is MWE:

\documentclass[a4paper]{book}

\usepackage[pagestyles]{titlesec} \newpagestyle{mapage}{% \setheadrule{1pt} \sethead[\color{red}\bfseries\toptitlemarks\sectiontitle--\bottitlemarks\sectiontitle][][\thepage/page header] {\thepage/page header}{}{\color{red}\bfseries\toptitlemarks\sectiontitle--\bottitlemarks\sectiontitle}%odd head \setfoot[][][]%even foot {}{\thepage}{} }

\usepackage{blindtext,multicol,xcolor} \begin{document} \pagestyle{mapage}

\begin{multicols}{3} \section{AA} \blindtext \section{BB} \blindtext \section{CC} \blindtext \section{DD} \blindtext \section{EE} \blindtext \section{FF} \section{GG} \section{HH} \blindtext \section{II} \section{JJ} \section{KK} \section{LL} \end{multicols}

\begin{multicols}{3} \section{MM} \section{NN} \section{OO} \blindtext \section{PP} \section{QQ} \section{RR} \section{SS} \section{TT} \section{UU} \blindtext \section{VV} \section{WW} \section{XX} \end{multicols}

\end{document}

enter image description here

Marcus
  • 91

1 Answers1

0

I have a solution using fancyhdr because I am more familiar with that than with titlesecs header stuff. I don't even know if my solution is easy to transform to titlesec.

My solution is to put all the section titles ina LaTeX3 seq (sequence), and to put the index of the section title in the seq in the mark. In the header I then extract those section titles between the first mark and the last mark of the page from this seq. Of course this is done with some LaTeX3 programming.

\documentclass[a4paper]{book}

\usepackage{fancyhdr} \usepackage{extramarks}

\pagestyle{fancy}

\ExplSyntaxOn

\seq_new:N \section_list \int_new:N \section_index

\renewcommand{\sectionmark}[1]{% \seq_gput_right:Nn \section_list {#1} \int_gincr:N \section_index \markright{\int_use:N \section_index} }

\fancyhead[LO,RE]{\thepage/page~header} \fancyhead[LE,RO]{ \color{red}\bfseries \seq_map_indexed_inline:Nn \section_list { \int_compare:nNnF {##1} < {\firstrightmark} { \int_compare:nNnTF {##1} < {\lastrightmark} {##2--} { \int_compare:nNnT {##1} = {\lastrightmark} {##2} } } } }

\ExplSyntaxOff

\usepackage{blindtext,multicol,xcolor} \begin{document} \begin{multicols}{3} \section{AA} \blindtext \section{BB} \blindtext \section{CC} \blindtext \section{DD} \blindtext \section{EE} \blindtext \section{FF} \section{GG} \section{HH} \blindtext \section{II} \section{JJ} \section{KK} \section{LL} \end{multicols}

\begin{multicols}{3} \section{MM} \section{NN} \section{OO} \blindtext \section{PP} \section{QQ} \section{RR} \section{SS} \section{TT} \section{UU} \blindtext \section{VV} \section{WW} \section{XX} \end{multicols} \end{document}

enter image description here

enter image description here

  • That's what I want! Many thanks for your answer! When I use three different fancy styles, I need to define a fancy style \fancypagestyle{bodystyle}{\fancyhf{}\fancyhead……} as in this example. But the error info shows that ! Illegal parameter number in definition of \temp@a. and You meant to type ## instead of #, right? How to avoid this error? Thanks again for your help! – Marcus Sep 30 '22 at 15:43