1

everybody.

I'm writing a book and I have a strange problem with the fancy style of the fancyhdr package. I need to show the title of my book on even pages and the title of the chapers on odd pages (indluding some pictures on the headings). This is the code that I used for setting the fancy style:

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\it \myfont \chaptername\ \thechapter.\ \normalfont \myfont #1}{}}%
\fancyhf{}\fancyhead[LE]{\makebox[0pt][l]{\hspace{-25mm}\raisebox{-4mm}{\includegraphcs[scale=1,bb=0 0 1 1]{image}}}%
\large \myfont \thepage \hspace{0.5cm} \it  \normalsize \myfont Book title}%
\fancyhead[RO]{\myfont \leftmark \hskip2em \normalfont \large \myfont \thepage}%
\fancyhead[LO]{\makebox[0pt][l]{\hspace{-190mm}\raisebox{-4mm}{\includegraphics[scale=1,bb=0 0 1 1]{image}}}}
\renewcommand*\headrulewidth{0pt}
\renewcommand*\footrulewidth{0pt}

That headings it has to be shown from Chapter 1 and on (mainmatter part), but, I need the myheadings style in the frontmatter. So, I called the myheadings style after the \frontmatter command and I called the fancy style after the \mainmatter command.

\begin{document}
\frontmatter
\pagestyle{myheadings}
\thispagestyle{empty}
\tableofcontents
\cleardoublepage
\include{Introduction}
\mainmatter
\pagestyle{fancy}
\include{chapter1}
.
.
.
\end{document}

The problem is that if I don't call the myheadings style (or I called the plain style, for example), the fancy style works perfectly. But when I call the myheadings style, the fancy style show the title of the book (even pages) and it doesn't show the chapter title (odd pages)!

How could I fix this strange behavior? I mean, how could I get that the fancy style shows the odd pages header even when I call the myheadings style in the fronmatter?

Thanks for your help.

EDIT: This is a compilable code.

\listfiles
\documentclass[reqno]{book}
\usepackage{makeidx}
\usepackage[spanish,es-nosectiondot]{babel}
\usepackage[utf8]{inputenc}
\usepackage{infwarerr}
\usepackage{color}
\usepackage{xcolor}
\usepackage{verbatim} %Para comentar bloques de texto
\usepackage[paperheight=254.81mm,paperwidth=184.81mm,text={130mm,186mm},centering]{geometry}
\usepackage{epsfig,graphicx,psfrag,float}
\usepackage[format=hang,labelsep=quad,textformat=period]{caption}%Configura el caption de las figuras
\usepackage{geometry}
\usepackage{ltxcmds}
\usepackage[all]{xy}
\usepackage{tocloft}% Este paquete modifica los parámetros de la Tabla de Contenidos (ToC)
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{sectsty}
\usepackage{enumerate}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{tcolorbox}
\usepackage{lettrine}
\usepackage{caption}
\usepackage{pdfpages}
\definecolor{Gris}{RGB}{233,233,233}
\definecolor{myGris}{RGB}{101,98,99}
\makeindex

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\it \chaptername\ \thechapter.\ \normalfont #1}{}}%Redefine la manera en que se muestra el capítulo en el encabezado
\fancyhf{}
\fancyhead[LE]{\makebox[0pt][l]{%Encabezado páginas pares, a la izquierda
\hspace{-25mm}\raisebox{-4mm}{}%\includegraphics[scale=1,bb=0 0 1 1]{franja_encabezados_pares.png}}%
} \large \thepage \hspace{0.5cm} \it  \normalsize Title of the Book}
\fancyhead[RO]{\leftmark \hskip2em \normalfont \large \thepage}%Encabezado páginas impares, a la derecha
\fancyhead[LO]{\makebox[0pt][l]{
\hspace{-190mm}\raisebox{-4mm}{}%\includegraphics[scale=1,bb=0 0 1 1]{franja_encabezados_impares.png}}%
  }}
\renewcommand*\headrulewidth{0pt}
\renewcommand*\footrulewidth{0pt}

\begin{document}
\frontmatter
\pagestyle{myheadings}
\begin{center}
TITLE OF THE BOOK
\end{center}
\newpage
\begin{center}
Authors
\end{center}
\newpage
\tableofcontents
\cleardoublepage
\chapter{Introduction}\thispagestyle{empty}
\lipsum[1-10]
\mainmatter
\pagestyle{fancy}
\pagenumbering{arabic}%A partir de aqui se enumeran las paginas con numeros arabigos
\chapter{Chapter 1}
\lipsum[11-16]
\section{Section 1}
\lipsum[17-25]
\chapter{Chapter 2}
\lipsum[26-35]
\section{Section 2}
\lipsum[36-50]
\end{document}
5
  • 2
    Hi Fabio, a few chucks of code are not helpful to give an answer. Please make your code compilable, so we can reproduce what you get.
    – Johannes_B
    Commented Jul 27, 2017 at 7:15
  • \it is 20+ years obsolete and ought not be used in LaTeX. Please update it.
    – cfr
    Commented Jul 27, 2017 at 23:49
  • Can you really not reproduce the issue with fewer packages?
    – cfr
    Commented Jul 27, 2017 at 23:49
  • 1
    Your preamble is a mess. You load the same packages multiple times, with different options. You load different packages for controlling the same aspect of the document. You load obsolete packages. You load packages in the wrong order. You are bound to have trouble.
    – cfr
    Commented Jul 28, 2017 at 0:02
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Commented Aug 18, 2017 at 16:08

2 Answers 2

2

I wouldn't, personally, mix myheadings with use of fancyhdr. I'd define a new style using the package's interface. However, it seems to work OK. The result looks odd to me: the chapter name etc. in upper case, the book title in italics and the page numbers large. Each to their own, I suppose.

The introduction should presumably be unnumbered, so you need to set the marks explicitly here.

\documentclass[reqno]{book}
\usepackage{makeidx}
\usepackage[spanish,es-nosectiondot]{babel}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[paperheight=254.81mm,paperwidth=184.81mm,text={130mm,186mm},centering]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{hyperref}
\definecolor{Gris}{RGB}{233,233,233}
\definecolor{myGris}{RGB}{101,98,99}
\makeindex

% \pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\itshape \chaptername\ \thechapter.\ \normalfont #1}{}}
\fancyhf{}
\fancyhead[LE]{\large\thepage\hspace{0.5cm} \itshape\normalsize Title of the Book}
\fancyhead[RO]{\leftmark\hskip 2em \normalfont\large\thepage}
\renewcommand*\headrulewidth{0pt}
\renewcommand*\footrulewidth{0pt}

\begin{document}
\frontmatter
\pagestyle{myheadings}% not recommended, but seems to work OK
\begin{titlepage}
  \begin{center}
    TITLE OF THE BOOK
  \end{center}
\end{titlepage}
\begin{center}
  Authors
\end{center}
\tableofcontents
\chapter*{Introduction}\markboth{\itshape Introduction}{}\thispagestyle{empty}
\lipsum[1-10]
\mainmatter
\pagestyle{fancy}
\chapter{Chapter 1}
\lipsum[11-16]
\section{Section 1}
\lipsum[17-25]
\chapter{Chapter 2}
\lipsum[26-35]
\section{Section 2}
\lipsum[36-50]
\end{document}

You don't need all the \newpage and \cleardoublepage and setting the page numbering and so on. You want the standard stuff anyway, so just let LaTeX do its thing.

0

You can re-issue commands such as \fancyhead within the body of your document, as often as you like.

For example, place this code immediately after \section{Section 1}:

\fancyhead[LE]{\makebox[0pt][l]{
\hspace{-25mm}\raisebox{-4mm}{}
} \large \thepage \hspace{0.5cm}  \normalsize NOT THE TITLE}

You can also leave \fancyhead empty. This works for custom headings, too.

1
  • 1
    \it is 20+ years obsolete, please update it.
    – cfr
    Commented Jul 27, 2017 at 23:48

You must log in to answer this question.

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