Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
1  
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

1 Answer 1

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

\documentclass[leqno,12pt,a4paper,oneside]{book}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\fancypagestyle{frontmatter}{%
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \renewcommand{\footrulewidth}{0pt}% No footer rule
  \fancyhf{}% Clear header/footer
  \fancyfoot[C]{\thepage}%
}
\fancypagestyle{mainmatter}{%
  \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
}
\begin{document}
\frontmatter%
\pagestyle{frontmatter}% frontmatter page style
\tableofcontents
\chapter{Preface}
\lipsum[1-20]% Some dummy text

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

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

share|improve this answer
2  
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
1  
@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

 
discard

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.