如何为首页目录添加页眉?

如何为首页目录添加页眉?

如何为首页目录、图表列表和表格列表添加页眉?

\documentclass[10pt,a4paper]{book}
%%%%%%%%%%%%Tikz%%%%
\usepackage[left=2cm,right=2cm,top=3.25cm,bottom=3cm]{geometry}
%%%%%%%%%%%%%%%%%%%%
\usepackage{fancyhdr}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{%
\markright{\thesection\ #1}}
\fancyhf{} % delete current header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt} % space for the rule
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers on plain pages
\renewcommand{\headrulewidth}{0pt} % and the line
}
    \renewcommand{\theequation}{\arabic{equation}}

\begin{document}
\tableofcontents
\listoffigures
\listoftables

\chapter{Cha}

\section{Sec}
\end{document}

答案1

目录等,并默认\chapter使用页面样式。要获得所需的效果,您需要将其更改为目录等的页面样式,但随后需要将样式恢复为其原始定义(当然,除非您希望在页面上显示标题,但我不喜欢这样做。这是 MWE 的修订版本,适用于多页目录。plainfancy\chapterplain\chapter

% tocheaderprob.tex  SE 560800

\documentclass[10pt,a4paper]{book}
%%%%%%%%%%%%Tikz%%%%
\usepackage[left=2cm,right=2cm,top=3.25cm,bottom=3cm]{geometry}
%%%%%%%%%%%%%%%%%%%%
\usepackage{fancyhdr}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{%
\markright{\thesection\ #1}}
\fancyhf{} % delete current header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt} % space for the rule
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers on plain pages
\renewcommand{\headrulewidth}{0pt} % and the line
}
    \renewcommand{\theequation}{\arabic{equation}}

\usepackage{comment}

\makeatletter
\let\ps@originplain\ps@plain % save definition of plain pagestyle
\makeatother

\addtolength{\textheight}{-0.6\textheight} % short pages

\begin{document}

\fancypagestyle{plain}{} % change plain pagestyle to fancy

\tableofcontents 

\listoffigures 

\listoftables
\clearpage  % make sure LoT typesetting is finished

\makeatletter
\let\ps@plain\ps@originplain % revert plain style to the original
\makeatother

% lots of chapters for a multi-page ToC 
\chapter{Cha}
Text

\section{Sec}
Text

\subsection{Subsec}
Text

\chapter{Cha}
Text

\section{Sec}
Text

\subsection{Subsec}
Text

\chapter{Cha}
Text

\section{Sec}
Text

\subsection{Subsec}
Text

\chapter{Cha}
Text

\section{Sec}
Text

\subsection{Subsec}
Text

\end{document}

相关内容