0

I am trying to write a document using the book class. I would like to have empty footers I also would like to have, on the header of each page, right-aligned, the chapter title (not capitalized) followed by a space and then the page number (yes, that includes the first pages of chapters). And I also want to add the unnumbered chapters to the table of contents. Please take a look at this MWE:

\documentclass{book}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\title{A title}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}
\fancyhead[R]{\footnotesize{\leftmark}\quad{\footnotesize{\thepage}}}
\makeatletter
\renewcommand{\chapter}{\cleardoublepage\@startsection
  {chapter}
  {0}
  {-\parindent}
  {\baselineskip}
  {\baselineskip}
  {\normalfont\Huge\textbf}}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introdução}
\lipsum[1-5]
\mainmatter
\chapter{A chapter}
\section{Start}
\lipsum[6-15]
\chapter{New chapter}
\end{document}

This almost achieves what I want. It does achieve what I want in the \mainmatter. The problem lies in the\frontmatter. As you can see if you compile it, the headers of the first four pages are “CONTENTS i”, “CONTENTS ii”, “CONTENTS iii”, and “CONTENTS iv”, whereas I am aiming at having “Contents i”, “Contents ii”, “Introduction i”, and “Introduction ii”. How can I achieve that?

1 Answer 1

2

Like this one:

\documentclass{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\nouppercase{\rightmark}}
\fancyhead[RE]{\bfseries\nouppercase{\leftmark}}
\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0pt}
%\addtolength{\headheight}{0.5pt}
\usepackage{emptypage}
\begin{document}
    \frontmatter
    \tableofcontents
    \chapter{Introduction}
    \lipsum[1-5]
    \mainmatter
    \chapter{A chapter}
    \section{Start}
    \lipsum[6-15]
    \chapter{New chapter}
    \chapter{A chapter}
    \section{Start}
    \lipsum[6-15]
    \chapter{New chapter}
    \chapter{A chapter}
    \section{Start}
    \lipsum[6-15]
    \chapter{New chapter}
    \chapter{A chapter}
    \section{Start}
    \lipsum[6-15]
    \chapter{New chapter}
    \chapter{A chapter}
    \section{Start}
    \lipsum[6-15]
    \chapter{New chapter}
    \chapter{A chapter}
    \section{Start}
    \lipsum[6-15]
    \chapter{New chapter}
    \chapter{A chapter}
    \section{Start}
    \lipsum[6-15]
    \chapter{New chapter}
    \chapter{A chapter}
    \section{Start}
    \lipsum[6-15]
    \chapter{New chapter}
\end{document}

Output:

enter image description here

EDIT: If You want page number like in Your question edit the corresponding lines this way:

%\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\nouppercase{\rightmark} \;\thepage}
\fancyhead[RE]{\bfseries \thepage \;\nouppercase{\leftmark}}

You must log in to answer this question.

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