0

I have the following WME:

\documentclass[twoside]{book}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}


\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}


\fancypagestyle{mypagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[OC]{\thechapter.\quad\chaptertitle}% Author on Odd page, Centred
  \fancyhead[EC]{\thechapter.\quad\chaptertitle}% Title on Even page, Centred
  \fancyfoot[C]{\thepage}%
  \renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}

\begin{document}

\pagestyle{mypagestyle}
\chapter{Introduction}
\lipsum[1-40]

\end{document}

Using this WME, the headers only display the chapter number. How can I get the headers to display the chapters name?

3
  • 1
    \chaptertitle is a titlesec command, not fancyhdr. I don't think both packages cooperate. – Bernard Jun 30 '17 at 14:30
  • How would you do it using fancyhdr? – user131526 Jun 30 '17 at 14:35
  • A priori, I don't know. I'll try to find a way, but it's much easier with titleps. – Bernard Jun 30 '17 at 17:01
2

You can do this with \leftmark.

leftmark

\documentclass[twoside]{book}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}


\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}


\fancypagestyle{mypagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[OC]{\leftmark}% Author on Odd page, Centred
  \fancyhead[EC]{\leftmark}% Title on Even page, Centred
  \fancyfoot[C]{\thepage}%
  \renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}

\begin{document}

\pagestyle{mypagestyle}
\chapter{Introduction}
\lipsum[1-40]

\end{document}

Here's a version without "CHAPTER":

without

\documentclass[twoside]{book}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}


\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}

\usepackage{expl3,xparse}
\ExplSyntaxOn
\cs_generate_variant:Nn \tl_set:Nn {Nx}
\NewDocumentCommand{\replace}{mmm}
 {
  \pintodoido_replace:nnn {#1} {#2} {#3}
 }

\tl_new:N \l_pintodoido_input_text_tl
\tl_new:N \l_pintodoido_search_tl
\tl_new:N \l_pintodoido_replace_tl

\cs_new_protected:Npn \pintodoido_replace:nnn #1 #2 #3
 {
  \tl_set:Nf \l_pintodoido_input_text_tl { #1 }
  \tl_set:Nn \l_pintodoido_search_tl { #2 }
  \tl_set:Nn \l_pintodoido_replace_tl { #3 }
  \regex_replace_all:nnN { \b\u{l_pintodoido_search_tl}\b } { \u{l_pintodoido_replace_tl} } \l_pintodoido_input_text_tl
  \tl_use:N \l_pintodoido_input_text_tl
 }
\ExplSyntaxOff

\fancypagestyle{mypagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[OC]{\replace{\leftmark}{Chapter}{}}% Author on Odd page, Centred
  \fancyhead[EC]{\replace{\leftmark}{Chapter}{}}% Title on Even page, Centred
  \fancyfoot[C]{\thepage}%
  \renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}

\begin{document}

\pagestyle{mypagestyle}
\chapter{Introduction}
\lipsum[1-40]

\end{document}
4
  • Sorry, but the /leftmark outputs the horrible 'Chapter 1. Introduction'. I want '1. Introduction'. How would you do this? – user131526 Jun 30 '17 at 16:09
  • @PintoDoido See the edited post. Commands from here. – TeXnician Jun 30 '17 at 16:55
  • Sorry you're code contains typos! Check out how many 'pintodoidos' you've got! – user131526 Jun 30 '17 at 17:25
  • @PintoDoido Where's that a typo? – TeXnician Jun 30 '17 at 17:30
1

You can use

\AtBeginDocument{%
    \renewcommand*\chaptermark[1]{\markboth{\thechapter.\quad#1}{}}%
}

to remove the chaptername from the header entry.

\documentclass[twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}

\usepackage{fancyhdr}
\AtBeginDocument{%
    \renewcommand*\chaptermark[1]{\markboth{\thechapter.\quad#1}{}}%
}
\fancypagestyle{mypagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[C]{\leftmark}%
  \fancyfoot[C]{\thepage}%
  \renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}

\usepackage{lipsum}% for dummy text
\begin{document}
\chapter{Introduction}
\lipsum[1-40]
\end{document}

enter image description here

Or maybe there is no need for an additional page style and you can use the fancy style:

\documentclass[twoside]{book}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\quad#1}{}}
\fancyhf{}% Clear header/footer
\fancyhead[C]{\leftmark}%
\fancyfoot[C]{\thepage}%

\usepackage{lipsum}% for dummy text
\begin{document}
\chapter{Introduction}
\lipsum[1-40]
\end{document}

The result is the same as above.

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.