0

I'd like the section title of the current section added to the header. I use unnumbered sections and that seems to be an issue for the titleps

\documentclass{book}

\usepackage{titleps}                            %Header,footer
\newpagestyle{main}{
    \sethead{}{}{\thesection\ \sectiontitle}
    \setfoot{}{}{Page \thepage}
}
\pagestyle{main}

\begin{document}

\section*{Introduction}

\newpage

\section{Introduction}

\end{document}

The code above adds in the case of a numbered section the following header result:

enter image description here

But unnumbered sections are not properly added to the header - only a zeroth-number is added and not the section title itself:

enter image description here

How do I fix this so I can display the current section title without any numbering shown, when I use unnumbered sections with \section*{...}?

0

1 Answer 1

1

It is necessary to add the section mark to the starred sections.

For a general solution a redefinition of the section command was used from here.

a2

\documentclass{book}

\usepackage{titleps}    
    
\newpagestyle{main}{% section
    \sethead{}{}{\thesection\ \sectiontitle}
    \setfoot{}{}{Page \thepage}
}

\pagestyle{main}
    
\usepackage{kantlipsum}% dummy text

%******************************************* added <<<<<<<<<<<<
%% From https://tex.stackexchange.com/a/245879/161015
\usepackage{xparse}

\renewcommand{\thesection}{\arabic{section}} % Do not use the chapter number (optional)

\newpagestyle{mainS}{%section*
    \sethead[][][\sectiontitle]{}{}{\sectiontitle}
    \setfoot{}{}{Page \thepage}
}

\let\oldsection\section
\makeatletter
\RenewDocumentCommand{\section}{s o m}{%
    \IfBooleanTF{#1}
    {\pagestyle{mainS}% \section*       
        \oldsection*{#3}% \section*[.]{..}
        \sectionmark{#3}% add the mark                  
    }{\pagestyle{main}% \section    
        \IfNoValueTF{#2}
        {\oldsection{#3}}% \section{..}
        {\oldsection[#2]{#3}}% \section[.]{..}
    }%
}
\makeatother
%*******************************************

\begin{document}    
    
    \section*{Introduction I}
    \kant[1-4]
    
    \section{Introduction II}
    \kant[1-4]
    
    \section*{Introduction III}
    \kant[1-4]
\end{document}

If you don't have a chapter before the first numbered section, you can suppress the 0. before the section number using

\renewcommand{\thesection}{\arabic{section}}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .