[Tex/LaTex] Problem with \chapter* and fancyhdr

chaptersfancyhdrtable of contents

I'm having a problem with \chapter*{} and fancyhdr. I want to start the first chapter of my thesis with a introduction section, appearing in the TOC but without numeration, that's why I use:

\chapter*{Introduccion} 

and

\addcontentsline{toc}{chapter}{Introduccion}

at the beginning of the Introduccion.tex file, but I don't know why, the fancyhdr header shows "list of tables" instead of "Introduccion"!

(the list of tables is immediately before the introduction).

Here is my code:

\documentclass[a4paper,12pt,twoside]{book}
%
\usepackage[bottom=25mm,top=25mm, left=30mm, right=25mm]{geometry}
%
\parskip=8pt
%
\widowpenalty=10000
\clubpenalty=10000
%
\usepackage[spanish, es-tabla]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{morefloats}
%
\setcounter{secnumdepth}{3}
\usepackage{eurosym}
\usepackage[pdftex]{graphicx}
\usepackage{pdfpages}
\usepackage[pagebackref=true]{hyperref}
\hypersetup{%
    bookmarks=true,         % barra de marcadores
    unicode=false,          % caracteres non-Latin en marcadores de Acrobat
    pdftoolbar=true,        % mostrar barra de herramientas de Acrobat
    pdfmenubar=true,        % mostrar menú de Acrobat
    pdffitwindow=false,     % ajustar ventana al ancho de página
    pdfstartview={FitH},    % ajustar documento al ancho de página
    pdftitle={Memoria PFC}, % título
    pdfauthor={},           % autor
    pdfsubject={},          % tema del documento
    pdfcreator={},          % generador del documento
    pdfproducer={},         % productor del documento
    pdfkeywords={},         % lista de palabras clave
    pdfnewwindow=true,      % enlaces en una nueva ventana
    colorlinks=true,        % false: enlaces en caja; true: enlaces coloreados
    linkcolor=blue,         % color de enlaces internos
    citecolor=green,        % color de enlaces a bibliografía
    filecolor=magenta,      % color de enlaces a ficheros
    urlcolor=blue           % color de enlaces externos
}
%
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[EL]{\nouppercase\leftmark}
\fancyhead[OR]{\nouppercase\rightmark}
\fancyhead[ER,OL]{\thepage}
%
\makeatletter
%
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
%
\begin{document}
%
\pagenumbering{gobble} % Las primeras paginas no quiero que se numeren
%
\includepdf[pages={-}]{./Archivos/Portada_PFCccompleto.pdf}
\input{./Archivos/Capitulos/pfc_dedicatoria}
\input{./Archivos/Capitulos/pfc_agradecimientos}
\include{./Archivos/Capitulos/pfc_abreviaturas}
%
% FRONTMATTER: TOC, LOF, LOT 
\frontmatter
%
\tableofcontents
\listoffigures
\listoftables
%
% MAINMATTER
%
\mainmatter
\include{./Archivos/Capitulos/pfc_intro}
\include{./Archivos/Capitulos/pfc_main_010}
...
%

Best Answer

This is a very common problem. The \chapter* command doesn't update the marks that are used for the headers, while \listoftables does.

So the result is that after

\mainmatter
\chapter*{Introduccion}

The simplest and more effective remedy is to issue

\markboth{Introduccion}{Introduccion}

since you're removing the usual uppercasing done by the book class; you could also, for doing like the \listof... commands, type

\markboth{\MakeUppercase{Introduccion}}{\MakeUppercase{Introduccion}}

so the style will be the same even if you eventually decide not to use fancyhdr.

However, the best option, in my opinion, is to number also the introduction and forget about all these problems.


A couple of words about your style. I prefer to have a package loading section and then a setup section in the preamble. Also, pdftex should not be passed to graphicx. Instead of redefining \cleardoublepage it's simpler to load the emptypage package.

I removed the settings to \clubpenalty and \widowpenalty to 10000, because this doesn't really solve the problems with club and widow lines. Reinstate them, if you prefer. Also setting a nonzero parskip should be avoided: it hinders readability rather than enhancing it, particularly in presence of short paragraphs, producing loads of white strips on the page.

Last, I added headheight=14.5pt as requested by fancyhdr.

Here's an edited version (kantlipsum is just for producing some nonsense text).

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

\usepackage[
  bottom=25mm,
  top=25mm,
  left=30mm,
  right=25mm,
  headheight=14.5pt,
]{geometry}

\usepackage[utf8]{inputenc}
\usepackage[spanish, es-tabla]{babel}

\usepackage{kantlipsum} % for populating the document

\usepackage{morefloats}
\usepackage{eurosym}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage{fancyhdr}
\usepackage{emptypage}
\usepackage[pagebackref=true]{hyperref}
\hypersetup{%
    bookmarks=true,         % barra de marcadores
    unicode=false,          % caracteres non-Latin en marcadores de Acrobat
    pdftoolbar=true,        % mostrar barra de herramientas de Acrobat
    pdfmenubar=true,        % mostrar menú de Acrobat
    pdffitwindow=false,     % ajustar ventana al ancho de página
    pdfstartview={FitH},    % ajustar documento al ancho de página
    pdftitle={Memoria PFC}, % título
    pdfauthor={},           % autor
    pdfsubject={},          % tema del documento
    pdfcreator={},          % generador del documento
    pdfproducer={},         % productor del documento
    pdfkeywords={},         % lista de palabras clave
    pdfnewwindow=true,      % enlaces en una nueva ventana
    colorlinks=true,        % false: enlaces en caja; true: enlaces coloreados
    linkcolor=blue,         % color de enlaces internos
    citecolor=green,        % color de enlaces a bibliografía
    filecolor=magenta,      % color de enlaces a ficheros
    urlcolor=blue           % color de enlaces externos
}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[EL]{\nouppercase\leftmark} 
\fancyhead[OR]{\nouppercase\rightmark}
\fancyhead[ER,OL]{\thepage}

\setcounter{secnumdepth}{3}

\begin{document}

\frontmatter

\tableofcontents
\listoffigures
\listoftables

\mainmatter

\chapter*{Introduccion}
\markboth{Introduccion}{Introduccion}

\kant

\chapter{Abc}

\section{Def}

\kant

\begin{table}
\caption{X}
\end{table}

\begin{figure}
\caption{Y}
\end{figure}

\kant

\end{document}

enter image description here

Related Question