\documentclass[twoside,11pt]{book}
\usepackage{fancyhdr,xcolor,lipsum}
\let\Chaptermark\chaptermark
\def\chaptermark#1{\def\Chaptername{#1}\Chaptermark{#1}}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
\colorlet{myfancycolor}{black}
\fancypagestyle{mystyle}{
\renewcommand*\footrulewidth{1pt}
\fancyfoot[OR]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hfil
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[OL]{%
\Chaptername
}
\fancyfoot[EL]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[ER]{%
\rightmark{
\footnotesize\textbf{INTRODUCTION TO MATLAB}
}
}
}
\pagestyle{mystyle}
\begin{document}
\frontmatter
\chapter{PREFACE}
\lipsum[1-5]
\tableofcontents
\mainmatter
\chapter{LALALA LALALA LALALA}
\lipsum[1-8]
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\end{document}
I have a problem in making footer. In \mainmatter
is no problem. In \frontmatter
there is a problem.
I want the even page the footer is book title (with page number) and the odd page is chapter name (with page number). The result in \mainmatter
is no problem. But in \frontmatter
, if I make chapter preface, the footer of TOC (in odd page) is "PREFACE". Also, in even page, "CONTENTS" appear with book title. (see my picture above)
Why the setting fancyhdr
is not in accordance with setting as for \mainmatter
?
How to make the setting fancyhdr
for \frontmatter
is same as for \mainmatter
?
ADDENDUM:
\documentclass[twoside,11pt]{book}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm,papersize={15.5cm,23.5cm}]{geometry}
\usepackage{fancyhdr,lipsum,xcolor,hyperref}
\let\Chaptermark\chaptermark
\def\chaptermark#1{\def\Chaptername{#1}\Chaptermark{#1}}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
\colorlet{myfancycolor}{black}
\fancypagestyle{mystyle}{
%\renewcommand*\footrulewidth{1pt}
\fancyfoot[OR]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hfil
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[OL]{%
\footnotesize\textbf{\nouppercase{\Chaptername}}%
}
\fancyfoot[EL]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[ER]{%
\footnotesize\textbf{INTRODUCTION TO MATLAB}%
}
}
\fancypagestyle{frontmatter}[mystyle]{
\fancyfoot[OL]{%
\footnotesize\textbf{\nouppercase{\Chaptername}}%
}
}
\begin{document}
\frontmatter
\pagestyle{frontmatter}
\chapter{PREFACE}
\lipsum[1-20]
{%
\cleardoublepage
\newpage
\renewcommand{\Chaptername}{CONTENTS}
\phantomsection\addcontentsline{toc}{chapter}{CONTENTS}
\tableofcontents
}%
\mainmatter
\pagestyle{mystyle}
\chapter{LALALA LALALA LALALA}
\lipsum[1-8]
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\end{document}
I have tried Pieter van Oostrum's answer and there is little modification from me.
But, the result in footer of contents is "PREFACE".
Best Answer
\rightmark
from the footer.That didn't make sense anyway, I think.\Chaptername
in the left footer, so you have to set that.Now, if you also are going to use the "capitalise words" trick in the footer, like in one of your previous questions, this will be changed to "Contents" instead of "CONTENTS". If you don't want that then you would need a
\fancyfoot[OL]
without the\mycapswords
. The safest way to do that is to define a pagestylefront matter
for that.Here is a complete example. NOTE: The
\fancypagestyle
with the optional argument needsfancyhdr
version 4.