2

I'm using fancydr like this:

\usepackage{titlesec} % Normal chapter titles
\titleformat{\chapter}{\normalfont\LARGE\bfseries}{\thechapter.}{1em}{}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\emph{\leftmark}}
\rhead{\nouppercase{\emph{\rightmark}}}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\space#1}{}} 
\setlength{\headheight}{15pt}

This doesn't work well with chapter*{}, as it leaves the last chapter's details to the header.

e.g. I have

\chapter{Conclusions and future directions}
\input{./tex/conclusions}

\chapter*{Summary}
\input{./tex/summary}
\addcontentsline{toc}{chapter}{Summary}

Then the pages in summary show Conclusions and future directions in their header. How could I make fancyhdr work with chapter*? and is there a possibility to disable the fancyhdr for some pages?

3
  • Add also \chaptermark{Summary} besides the \addcontentsline command.
    – egreg
    May 24, 2015 at 12:43
  • 1
    @egreg Thanks, almost perfect, but is there a way to remove the number in front of the title in header. e.g. I currently get 0. Abbrevations and Symbols, but I'd like just Abbrevations and Symbols. the alternative, which might even be better is to disable fancyhdr for some pages, is this possible?
    – eimrek
    May 24, 2015 at 13:04
  • titlesec discourages the use of starred versions of sectional units.
    – Werner
    May 24, 2015 at 17:29

1 Answer 1

3

You should define \chaptermark in a better way:

\renewcommand{\chaptermark}[1]{%
  \markboth{%
    \ifnum\value{chapter}>0
      \thechapter.\space
    \fi
    #1%
  }{}%
}

so “0.” will not be added when the chapter number is zero (that is, for the chapters before the first).

For the conclusion, use

\chapter*{Summary}
\addcontentsline{toc}{chapter}{Summary}\markboth{Summary}{}
\input{./tex/summary}

Notice the different order, because you want to execute those commands at the start of the chapter text, not at the end.

4
  • When I try to redefine the chaptermark, I get the error: ! Package titlesec Error: Entered in horizontal mode.. In the fancyhdr definition I also have a \renewcommand for \chaptermark, maybe I could add something to that?
    – eimrek
    May 24, 2015 at 14:06
  • I see no mention of \titlesec in the question. My feeling is that you're adding the \renewcommand in a wrong place.
    – egreg
    May 24, 2015 at 14:07
  • I added the titlesec header in the question. When I put your \renewcommand{\chaptermark} after the fancyhdr stuff, I get the error, but before that I won't get the error and it doesn't do anything (gets overwritten by the fancyhdr redefinition of chaptermark, see the OP)
    – eimrek
    May 24, 2015 at 14:14
  • @Shepherd Sorry, I forgot a \markboth! Note that \markboth should be used for the summary (not \chaptermark).
    – egreg
    May 24, 2015 at 14:16

You must log in to answer this question.

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