1

I have the problem, that in my header "chapter" is mentioned, but I only want the chapter number and name to appear.

\documentclass[a4paper, openany]{book}
\usepackage{fancyhdr}
\usepackage{titlesec}

\titleformat{\chapter}{\normalfont\huge}{\Huge \bf \thechapter}{20pt}{\Huge \bf} %This is here, so that at each chapter start, I only get "chapter number + chapter name"
\fancyhead[RO]{\rightmark}
\fancyhead[LE]{\leftmark}
\fancyfoot[RO,LE]{\thepage}

\begin{document}

\chapter{dsfjdj}
\newpage

\end{document}

The right mark works the way I want it to, but the left mark doesn't, since it also lists the word "chapter" explicitly. How can I avoid it?

lockstep
  • 250,273
Zyrax
  • 115

2 Answers2

1

Since you use titlesec, I suggest you use titleps, which is easier to use than fancyhdr, in my opinion. It allows to define a new page style without using marks with a simple syntax:

\documentclass[a4paper, openany]{book}

\usepackage[pagestyles]{titlesec}
\usepackage{titlecaps}

\titleformat{\chapter}{\normalfont\huge \bfseries}{\Huge \thechapter}{20pt}{\Huge} %This is here, so that at each chapter start, I only get "chapter number + chapter name"

\newpagestyle{myps}{%
\sethead[\small\scshape\thechapter. ~\titlecap{\chaptertitle}][][]{}{}{\small\thesection.~\itshape\sectiontitle}
\setfoot{}{\thepage}{}
}%

\usepackage{lipsum}
\pagestyle{myps}

\begin{document}

\chapter{A first chapter}
\lipsum[1-3]
\section{Some section}

\lipsum

\end{document} 

enter image description here enter image description here

Bernard
  • 271,350
  • I tried it, unfortunately it did not work, since I use \renewcommand{\headrulewidth}{0.4pt} in between and those two seem to interfere with each other. – Zyrax Aug 31 '16 at 23:40
  • Yes, don't load both fancyhdr and titlepsIf you want a headrule (there's none by default, contrary to fancyhdr), you just have to mention \headrule in the description of the page style. Thickness (0.4pt by default), is changed with, say, \setheadrule{0.8pt}. – Bernard Sep 01 '16 at 01:14
0

I used the link posted by @John Kormylo and modified it a bit. This way, I get the desired result.

\documentclass[a4paper, openany]{book}
\usepackage{fancyhdr}
\usepackage{titlesec}

\titleformat{\chapter}{\normalfont\huge}{\Huge \bf \thechapter}{20pt}{\Huge \bf} %This is here, so that at each chapter start, I only get "chapter number + chapter name"
\fancyhead[RO]{\rightmark}
\fancyhead[LE]{\leftmark}
\fancyfoot[RO,LE]{\thepage}

\makeatletter
  \renewcommand*{\chaptermark}[1]{%
    \markboth{
        \uppercase{\thechapter \, #1}
    }{}%
  }%
\makeatother

\makeatletter
  \renewcommand*{\sectionmark}[1]{%
    \markright{%
        \uppercase{\thesection \, #1}
    }{}%
  }%
\makeatother

\begin{document}

\chapter{dsfjdj}
\newpage

\end{document}
Zyrax
  • 115