当前页面名称与其他章节重叠

当前页面名称与其他章节重叠

我在 latex 上写论文,每页底部都显示当前章节的名称。代码如下:

\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}

在我的主文件中,我有一章用于致谢,然后是目录,然后我插入论文的不同部分,\include{ChapterX} 然后我包括参考书目。

但是,使用此代码,我在目录页的底部写了“致谢”,并在参考书目页面上写了最后一章的名称。

除了致谢部分,我列出的所有章节都已列出,问题出在那里吗?如果需要代码的其他部分,请告诉我。

目录中的错误示例

答案1

\fancyfoot[LO,RE]{\currentname}

在页脚中定义每一页的章节名称。对于编号或未编号章节的第一页,页面样式默认为 ,plain而不是fancy。如果您想以相同的方式重新定义它,请使用

\fancypagestyle{plain}{%
  \fancyhf{} % clear all header and footer fields
  \fancyfoot[LO,RE]{\currentname}%
  \fancyfoot[RO,LE]{\thepage}%
}

相关内容