4

I've found an answer to my question for a Memoir Class (Memoir class: turn off section numbering but still have header), but I can't get it to work for a book.

Basically, I want to suppress the numbering of sections, but I still want to be able to have my section names appear in my headers.

The code below works fine in section 2, but, in section 1, where I suppress the numbering, I also lose the header.

\documentclass[a4paper]{book}

\usepackage{fancyhdr,blindtext}
\pagestyle{fancy}
\fancyfoot{}
\fancyhead[RO,LE]{\thepage}
\fancyhead[LO]{\slshape \leftmark}
\fancyhead[RE]{\slshape \rightmark}

\usepackage{blindtext}

\begin{document}

% Global font
\renewcommand{\rmdefault}{ppl}
\fontencoding{T1}
\fontfamily{ppl}
\fontsize{14}{18}
\selectfont

% Start the chapters here:

\chapter{Preface}

\section*{Section 1}

\blindtext
\blindtext
\blindtext
\blindtext
\blindtext

\section{Section 2}

\blindtext
\blindtext
\blindtext
\blindtext
\blindtext


\end{document}
4

This is easy with the package titlesec.

Load it as

\usepackage[pagestyles]{titlesec}

instead of loading fancyhdr.

Then, to have your section without printed numbers, define

\titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{}

and to have the headers like you want,

\newpagestyle{fancy}{
\setheadrule{0.4pt}
\sethead[\thepage][][\textsl{\MakeUppercase{\sectiontitle}}]% even
{\textsl{\MakeUppercase{\chaptername\ \thechapter. \ \chaptertitle}}}{}{\thepage}% odd
}
\pagestyle{fancy}

MWE:

\documentclass[a4paper]{book}

\usepackage{blindtext}

\usepackage[pagestyles]{titlesec}
\titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{}

\newpagestyle{fancy}{
\setheadrule{0.4pt}
\sethead[\thepage][][\textsl{\MakeUppercase{\sectiontitle}}]% even
{\textsl{\MakeUppercase{\chaptername\ \thechapter. \ \chaptertitle}}}{}{\thepage}% odd
}
\pagestyle{fancy}


\begin{document}

% Global font
\renewcommand{\rmdefault}{ppl}
\fontencoding{T1}
\fontfamily{ppl}
\fontsize{14}{18}
\selectfont

% Start the chapters here:

\chapter{Preface}

\section{Section 1}

\blindtext
\blindtext

\section{Section 2}

\blindtext
\blindtext
\blindtext
\blindtext
\blindtext


\end{document} 

Output:

enter image description here

| improve this answer | |
  • This is great; thanks very much. I think I'll opt for this particular solution since it allows me to continue to use the standard \section tag, which then makes my text easier to cut and paste into other docs. – James Bejon Jan 4 '15 at 13:14
  • @JamesBejon You're welcome. Glad it helped. – karlkoeller Jan 4 '15 at 13:14
3

You can define a new command

\newcommand\mysection[1]{%
  \section*{#1}%
  \markright{\MakeUppercase{#1}}% for the header
}

enter image description here

Code:

\documentclass[a4paper]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot{}
\fancyhead[RO,LE]{\thepage}
\fancyhead[LO]{\slshape \leftmark}
\fancyhead[RE]{\slshape \rightmark}

\newcommand\mysection[1]{%
  \section*{#1}%
  \markright{\MakeUppercase{#1}}% for the header
}

\usepackage{blindtext}
\begin{document}
\chapter{Preface}
\mysection{Section 1}
\Blindtext[10]
\section{Section 2}
\Blindtext[10]
\end{document}

Or maybe you can use the KOMA-Script class scrbook. There is a command \addsec to get an unnumbered section that appears in the header and in the tableofcontents.

\documentclass[11pt,headsepline,chapterprefix]{scrbook}
\usepackage[pagestyleset=standard]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\pagemark}
\cfoot[\pagemark]{}
\lohead{\leftmark}
\rehead{\rightmark}

\usepackage{blindtext}
\begin{document}
\chapter{Preface}
\addsec{Section 1}
\Blindtext[10]
\addsec{Section 2}
\Blindtext[10]
\end{document}

Or you can simple use

\setcounter{secnumdepth}{0}

if only parts and chapters should be numbered.

\documentclass[a4paper]{book}
\setcounter{secnumdepth}{0}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot{}
\fancyhead[RO,LE]{\thepage}
\fancyhead[LO]{\slshape \leftmark}
\fancyhead[RE]{\slshape \rightmark}

\usepackage{blindtext}
\begin{document}
\tableofcontents
\chapter{Preface}
\section{Section 1}
\Blindtext[10]
\section{Section 2}
\Blindtext[10]
\end{document}
| improve this answer | |
  • First solution works fine; thanks. I still had numbered sections when I used the KOMA-Script solution though; maybe I did something wrong... – James Bejon Jan 4 '15 at 13:16
  • I thought there were both unnumbered and numbered sections in the document. But if only parts and chapters should be numbered, you can simple use \setcounter{secnumdepth}{0}. – esdd Jan 4 '15 at 17:32

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.