TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having some problems with the fancyhdr package. How can I achieve the following in my big thesis file: The header should consists of the chapter name at the left side and the page number at the right side. The page with number 1 should be the first page of the first chapter. The "fancy" style should start after the table of contents and everything before should be enumerated with the letter i, ii and so on.

share|improve this question
Are you using twoside? What document class are you using? – Werner Jun 1 '12 at 19:21
I am using \documentclass[leqno,12pt,a4paper,oneside]{book} – Nadori Jun 1 '12 at 19:24
up vote 8 down vote accepted

In the following MWE I've created two different page styles: frontmatter and mainmatter. Your typical document structure will most likely include resetting the page style between these document components, including a call to \frontmatter/mainmatter to reset the page number and presentation (\roman and \arabic) as well as other ToC-related stuff:

enter image description here

\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \renewcommand{\footrulewidth}{0pt}% No footer rule
  \fancyhf{}% Clear header/footer
  \renewcommand{\headrulewidth}{.4pt}% Header rule
  \renewcommand{\footrulewidth}{.4pt}% Footer rule
  \fancyhf{}% Clear header/footer
  \fancyhead[L]{\leftmark}% Chapter in header Left
  \fancyhead[R]{\thepage}% Page number in header Right
\pagestyle{frontmatter}% frontmatter page style
\lipsum[1-20]% Some dummy text

\pagestyle{mainmatter}% mainmatter page style
\lipsum[1-20]% Some dummy text

You don't mention any hyperref-compatibility requirement. However, that could also be incorporated.

share|improve this answer
Why not using \frontmatter and \mainmatter instead of the \pagenumbering commands? You may include the page style choice in them. In this way you don't need \chapter* and \chapter{Preface} will not provide a number, but will make a TOC entry automatically. – egreg Jun 1 '12 at 19:52
@egreg: I've updated accordingly, thanks. – Werner Jun 2 '12 at 0:31
I have one small problem. The first chapter after the contents is the intruduction. I used \chapter*{Introduction}. How can I make sure this appears also in the list of contents (without a number). – Nadori Jun 3 '12 at 17:40
@Nadori: Use \chapter*{Introduction} \addcontentsline{toc}{chapter}{Introduction}. I would also suggest adding another page style (say, introduction) that provides clears Left header of \leftmark, otherwise you'll see "CHAPTER 0. Preface". With the other page styles created, it should be no problem to figure out what you want introduction to contain. – Werner Jun 4 '12 at 2:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.