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?

  • can you please make your code complete? – touhami Aug 31 '16 at 18:29
  • See tex.stackexchange.com/questions/120603/… for example. – John Kormylo Aug 31 '16 at 19:34
  • You may like to take a look at Does it matter if I use \textit or \it, \bfseries or \bf, etc :-) – Tobi Aug 31 '16 at 21:27
  • @John Kormylo Thanks that worked. Now I only see chapter number and chapter title in the header. But now, the thing is: it is not written in the same style, as it is when I use leftmark. How could I change the code that was posted there, to make it look like it was written with leftmark? – Zyrax Aug 31 '16 at 21:51
  • Book class uses \MakeUppercase{...} to create the chapter head. – John Kormylo Sep 1 '16 at 3:46
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

  • 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 1 '16 at 1: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}

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.