24

I need to display the chapter name with the \chapter* command to the left side of the header. This is one example of what I tried:

    \documentclass[12pt,a4paper,oneside]{book}
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \lhead{}
    \chead{}
    \rhead{\fancyplain{}{\textit{\leftmark}}}

    \begin{document}
    \chapter*{\centerline{Chapter Name}}

    \end{document}

How can I do this?

25

Try

\chapter*{chapter name}
\markboth{chapter name}{}

And consider using titlesec package rather using \centerline as a visual formatting approach.

  • 3
    Ok, using this command in the header appears "Chapter0. Chapter Name". I would like having only the chapter name, without "Chapter0". – Ford Prefect Jan 8 '13 at 20:31
  • 2
    @FordPrefect sorry. comes from not thinking ... nice to get 3 votes for a wrong solution. People give too much credit :-) – Frank Mittelbach Jan 8 '13 at 20:55
9

Setting the headers with fancyhdr usually requires changing the \chaptermark and \sectionmark commands; you don't need the latter, as you want only the chapter title in the header.

Here's an example in which I show two methods. A simple \chapter command in the \frontmatter will not give a numbering and correctly set the header. If you want the unnumbered chapter in the \mainmatter, then you can use an explicit \chaptermark command.

\documentclass[12pt,a4paper,oneside]{book}

\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\fancyhf{} % clear the headers
\fancyhead[R]{%
   % We want italics
   \itshape
   % The chapter number only if it's greater than 0
   \ifnum\value{chapter}>0 \chaptername\ \thechapter. \fi
   % The chapter title
   \leftmark}
\fancyfoot[C]{\thepage}

\fancypagestyle{plain}{
  \renewcommand{\headrulewidth}{0pt}
  \fancyhf{}
  \fancyfoot[C]{\thepage}
}

\setlength{\headheight}{14.5pt}

\usepackage{kantlipsum} % for the mock text

\begin{document}

\frontmatter

\chapter{Introduction}

\kant

\mainmatter

\chapter*{Another introduction}
\chaptermark{Another introduction}

\kant

\chapter{Title}

\kant

\end{document}

Note that if you plan to use appendices, one of the commands should be modified:

\makeatletter
\fancyhead[R]{%
   % We want italics
   \itshape
   % The chapter number only if it's greater than 0
   \ifnum\value{chapter}>0 \@chapapp\ \thechapter. \fi
   % The chapter title
   \leftmark}
\makeatother

(Unfortunately, the command that holds either \chaptername or \appendixname is an internal one, so one has to do some tricks to access it.)

Note also the \setlength{\headheight}{14.5pt} to give the header the room it needs.

For centering the chapter title it's better to use the methods of the titlesec or sectsty packages than doing explicit formatting.

Note This assumes that the unnumbered chapter is in the \frontmatter (any number of them, actually) or there is only one at the beginning of the \mainmatter. For other cases a more complex approach should be taken.

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.