1

I am writing my thesis on latex, and every pages show at the bottom the name of the current chapter. The code is the following:

\documentclass[openany, a4paper, 12pt]{book}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[top=4cm, bottom=4cm, left=3.5cm, right=3.5cm]{geometry}
\usepackage{indentfirst}
\usepackage{xcolor}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{enumitem}
\usepackage{pdfpages}
\usepackage{transparent}
\usepackage{float}
\usepackage[hidelinks]{hyperref}
\usepackage{makeidx}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{nameref}


\makeindex

\makeatletter
\pretocmd{\chapter}{\addtocontents{toc}{\protect\addvspace{-2\p@}}}{}{}
\pretocmd{\section}{\addtocontents{toc}{\protect\addvspace{-4\p@}}}{}{}

\newif\if@chapters
\@ifundefined{chapter}{\@chaptersfalse}{\@chapterstrue}
\if@chapters
  \apptocmd{\@chapter}{\gdef\currentname{#1}}{}{}
%  \apptocmd{\@schapter}{\gdef\currentname{#1}}{}{}
\fi
%\apptocmd{\@sect}{\gdef\currentname{#7}}{}{}
\def\currentname{---Still no title given---}
\makeatother

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{Fully Homomorphic Encryption over an Artificial Neural Network}
\fancyfoot[LO,RE]{\currentname}
\fancyfoot[LE,RO]{\thepage}


\renewcommand{\numberline}[1]{#1~}

\hypersetup{
    backref=true,
    pagebackref=true,
    allcolors=black
}

\setlength{\parskip}{8pt}




\begin{document}

\chapter*{Acknowledgements}
\printindex
Text...
\clearpage{\thispagestyle{empty}\cleardoublepage}  

\tableofcontents


\mainmatter
\chapter{test1}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\printindex
\clearpage{\thispagestyle{empty}\cleardoublepage}  
\phantomsection
\chapter{test2}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\printindex
\clearpage{\thispagestyle{empty}\cleardoublepage}  
\phantomsection
\chapter{test3}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\printindex
\clearpage{\thispagestyle{empty}\cleardoublepage}  
\phantomsection
\chapter{test4}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\section{test}
\subsection{test}
\printindex
\clearpage{\thispagestyle{empty}\cleardoublepage}  
\phantomsection

\chapter*{Conclusion}
Conclusion

\printindex
\clearpage{\thispagestyle{empty}\cleardoublepage}  
\phantomsection

\backmatter

\begin{thebibliography}{99}
\end{thebibliography}
\end{document}

On my main file, I have a chapter for the Acknowledgments, then the Contents, and then I insert the different part of my thesis \include{ChapterX} then I include the bibliography.

However, with this code, I have ''Acknowledgements'' written in the bottom of the pages of the Contents and the name of the last chapter on the pages for the bibliography.

All my chapters are listed except actually Acknowledgements, does the problem come from there? If other parts of the code are required, please let me know.

Example of error in the table of contents

  • (1) Welcome, (2) please provide a full (but minimal) example instead of a sniplet like this. An MWE makes it a lot easier for others to help as they can just copy your code and test is as is. Here we have to guess a lot, and thus a lot of people pass your question as there are others that are easier to approach – daleif May 28 at 12:57
  • I just edited the first message, I hope this is enough (the missing parts are only the modifications of layouts for theorems, definition, etc... so i don't think it's relevant here) – Robin S. May 28 at 13:06
  • You are including files (chapters) that we do not have access to, perhaps replce those include lines with some relevant sample data – daleif May 28 at 13:24
  • I mean the chapters have nothing specific, just a bunch of sections loaded with texts... – Robin S. May 28 at 13:29
  • I edited the first message to show the layout of chapters – Robin S. May 29 at 1:02
1
\fancyfoot[LO,RE]{\currentname}

defines on every page the chapter name in the footer. For the first page of a numbered or unnumbered chapter the page style is by default plain and not fancy. If you want to redefine it in the same way then use

\fancypagestyle{plain}{%
  \fancyhf{} % clear all header and footer fields
  \fancyfoot[LO,RE]{\currentname}%
  \fancyfoot[RO,LE]{\thepage}%
}
  • With your correction, it actually inverses my problem... Now "Acknowledgements" is visible on the footer of the first page of the TOC only, instead of all the other pages of the TOC – Robin S. May 29 at 8:15
  • I found something which is part of a solution, while not so elegant. I wrote \AtBeginDocument{\addtocontents{toc}{\protect\thispagestyle{fancy}{ \fancyhf{} % clear all header and footer fields \fancyfoot[RO,LE]{\thepage}}}} However now, while I don't have this problem, I have only roman notations for the page numbers inside the TOC, and all page numbers in the following footers are stuck at '1' – Robin S. May 29 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.