2

I want to remove the section numbering and then number subsections independently, resetting every chapter.

Pictorially,

1 Chapter
    First section
        1.1 subsection
        1.2 subsection
    Second section
        1.3 subsection     
2 Chapter
    First section
        2.1 subsection
        ...

If I do

\section*{Sectionname}
\addcontentsline{toc}{section}{Sectionname}

then I almost get what I want. However, the section name no longer appears as a fancyheader.

I am using the following code to create the headers:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot{} 
\fancyhf{}
\fancyhead[LE,RO]{\thepage} 
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead[RE]{\itshape \nouppercase{\leftmark}} 
\fancyhead[LO]{\itshape \nouppercase{\rightmark}} 

Could someone help?

2
  • 2
    If all your sections are unnumbered, why not load titlesec and format sections so they're considered as ‘normal’?sections, but no number is displayed?
    – Bernard
    Apr 18, 2018 at 9:01
  • Thank you! I like your clean solution, but as you say, the solution below is a bit more flexible. Apr 18, 2018 at 9:18

2 Answers 2

2

The easiest* way is to add \markright{Sectionname} to all of your sections. For this MWE, I defined a macro \mysection to execute the then three macros per section:

\documentclass{book}
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot{} 
\fancyhf{}
\fancyhead[LE,RO]{\thepage} 
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead[RE]{\itshape \nouppercase{\leftmark}} 
\fancyhead[LO]{\itshape \nouppercase{\rightmark}}

\newcommand{\mysection}[1]{%
    \section*{#1}%
    \addcontentsline{toc}{section}{#1}%
    \markright{#1}%
}
\renewcommand{\thesubsection}{\arabic{chapter}.\arabic{subsection}}

\begin{document}

\tableofcontents

\chapter{First Chapter}
\lipsum[1-2]
\mysection{First Section}
\lipsum[2-3]
\subsection{First Subsection}
\lipsum[3-4]
\subsection{Second Subsection}
\lipsum[4-5]
\mysection{Second Section}
\lipsum[5-6]
\subsection{Third Subsection}
\lipsum[6-7]
\chapter{Second Chapter}
\lipsum[7-8]
\mysection{Third Section}
\lipsum[8-9]
\subsection{Fourth Subsection}
\lipsum[9-10]

\end{document}

Table of contents: enter image description here

Section name in headings: enter image description here

Footnote: This is "easy" in the sense that it changes the structure of your approach minimally. A solution with titlesec will probably be "easier" in the sense that once the configuration has been done, changing the appearance or adding new sections becomes really easy.

0
0

With a KOMA-Script class (as in your question here) you can use \addsec:

\documentclass{scrbook}
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot{} 
\fancyhf{}
\fancyhead[LE,RO]{\thepage} 
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead[RE]{\itshape \nouppercase{\leftmark}} 
\fancyhead[LO]{\itshape \nouppercase{\rightmark}}

\RedeclareSectionCommand[
  counterwithout=section,
  counterwithin=chapter
]{subsection}

\begin{document}
\tableofcontents
\chapter{First Chapter}
\lipsum[1-2]
\addsec{First Section}
\lipsum[2-3]
\subsection{First Subsection}
\lipsum[3-4]
\subsection{Second Subsection}
\lipsum[4-5]
\addsec{Second Section}
\lipsum[5-6]
\subsection{Third Subsection}
\lipsum[6-7]
\chapter{Second Chapter}
\lipsum[7-8]
\addsec{Third Section}
\lipsum[8-9]
\subsection{Fourth Subsection}
\lipsum[9-10]
\end{document}

But then it is also recommended to use package scrlayer-scrpage for header and footer:

\documentclass{scrbook}
\usepackage{lipsum}

\usepackage[automark,headsepline]{scrlayer-scrpage}
\clearmainofpairofpagestyles
\ohead{\pagemark}
\ihead{\headmark}
\renewcommand\chaptermarkformat{}

\RedeclareSectionCommand[
  counterwithout=section,
  counterwithin=chapter
]{subsection}

\begin{document}
\tableofcontents
\chapter{First Chapter}
\lipsum[1-2]
\addsec{First Section}
\lipsum[2-3]
\subsection{First Subsection}
\lipsum[3-4]
\subsection{Second Subsection}
\lipsum[4-5]
\addsec{Second Section}
\lipsum[5-6]
\subsection{Third Subsection}
\lipsum[6-7]
\chapter{Second Chapter}
\lipsum[7-8]
\addsec{Third Section}
\lipsum[8-9]
\subsection{Fourth Subsection}
\lipsum[9-10]
\end{document}

Result:

enter image description here

enter image description here

You must log in to answer this question.

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