我目前正在尝试为项目报告设置文档。页眉和页脚方面我遇到了困难。
我希望每页的页脚页脚应如下图所示。
为了实现这个页脚,我目前正在fancyhdr
使用花式页面样式如下面的代码片段所示。
\pagestyle{fancy}
%% FOOTER
\fancyfoot[C]{\small \thepage} % PAGE NUMBER
\fancyfoot[L]{\small ENEL895 \\ Version 1.0} % PAPER CODE AND VERSION
\fancyfoot[R]{\small \today} % TODAY'S DATE
\renewcommand{\footrulewidth}{1pt} % FOOTER RULE LINE
我遇到的页脚问题是针对目录的(我已将其放在\thispagestyle{fancy}
目录和所有章节旁边,以尝试获取页眉和页脚)。目录是分布在 2 页,第一页只有页脚的页码,而第二页有正确的页眉和页脚。
标头部分比较复杂。对于标头,我需要所有前页(第一章之前的所有内容)章节标题在右边标题和字母的大小写应与标题大小写完全相同(即没有大写和不是斜体)。目录标题(如上所示)就是我的意思的一个示例。至于章节,我希望第一章页面没有页眉,只有上面指定的页脚。对于章节的其余页面,我希望章节位于页眉左侧(格式:章节 # - 章节名称),部分位于页眉右侧(格式:# 部分名称)。
页眉和页脚本章剩余页面应该看起来像下面的图片一样(忽略我已经展示了章节第一页的事实)。
我在标题方面遇到的另一个困难是附录标题有章节 A 而不是附录 A。我希望它位于标题的左侧,并且附录的第一页应该没有标题(就像章节一样)。
附录标题难度:
这是迄今为止我的文档的 MWE(抱歉,它有很多评论,并且输出与本线程中显示的图像不一样)。
\documentclass[12pt,a4paper]{report}
%----------------------------------------------------------------------------------------
% PACKAGES
%----------------------------------------------------------------------------------------
%% PAGE MARGINS
\usepackage[margin=1in]{geometry}
%% RANDOM LOREM IPSUM TEXT TO FILL
\usepackage{blindtext}
%% TOC BABEL
\usepackage[english]{babel}
%% HYPERLINKING
\usepackage[colorlinks=true]{hyperref}
\hypersetup{%
colorlinks,
linkcolor={red!50!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}
%% HEADERS AND FOOTERS
\usepackage{fancyhdr}
%% HEADING TITLES (TITLE SECTIONS)
\usepackage{titlesec}
%% MAKES THE TOC WORK BETTER IMO (NOT SURE HOW)
\usepackage{tocloft}
%% INCLUDE PDF PAGES
\usepackage{pdfpages}
%----------------------------------------------------------------------------------------
% PAGE STYLE - HEADERS AND FOOTERS SETUP
%----------------------------------------------------------------------------------------
\pagestyle{fancy}
%% HEADER
\fancyhead[L]{\leftmark} % SECTION NAME-FIRST SECTION/PREVIOUS SECTION
\fancyhead[R]{\nouppercase{\rightmark}} % CHAPTER NAME
%--------------------------------------------------------------------------
%% FOOTER
\fancyfoot[C]{\small \thepage} % PAGE NUMBER
\fancyfoot[L]{\small ENEL895 \\ Version 1.0} % PAPER CODE AND VERSION
\fancyfoot[R]{\small \today} % TODAY'S DATE
\renewcommand{\footrulewidth}{1pt} % FOOTER RULE LINE
%--------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
% REDEFINING CHAPTER AND SECTION (LEFT AND RIGHT MARKS) TO BE THE % CHAPTER & SECTION NAMES AND NOT CAPITALISED.
%----------------------------------------------------------------------------------------
%% CHAPTER DEFINED AS RIGHT MARK (Chapter # - Chapter Name)
\renewcommand{\chaptermark}[1]{%
\markboth{}{\chaptername
\ \thechapter ~- #1}}
%% SECTION DEFINED AS LEFT MARK (# Section Name)
\renewcommand{\sectionmark}[1]{\markboth{\thesection\ #1}{}}
%----------------------------------------------------------------------------------------
% REDEFINE THE CHAPTER HEADING FORMAT AND VERTICAL SPACING
%----------------------------------------------------------------------------------------
%% SIZE AND FORMAT OF CHAPTER HEADING TITLE
\titleformat{\chapter}[display]
{\normalfont\Huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
% ALTERS "BEFORE" SPACING (SECOND ARGUMENT) TO 0
\titlespacing*{\chapter}{0pt}{0pt}{20pt}
%----------------------------------------------------------------------------------------
% EDITING THE TOC TITLE AND DOTTED LINE SEGMENTS FOR CHAPTERS
%----------------------------------------------------------------------------------------
%% CHANGE TITLE TO "Table of Contents"
\addto\captionsenglish{% Replace "english" with the language you use
\renewcommand{\contentsname}%
{Table of Contents}%
}
%% ADD DOTTED LINES FOR CHAPTERS IN TOC
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % for chapters, if you really want!
%----------------------------------------------------------------------------------------
% CHANGE LINE SPACING TO 1.5
%----------------------------------------------------------------------------------------
\renewcommand{\baselinestretch}{1.5}
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
% END OF PREAMBLE AND START OF DOCUMENT
%----------------------------------------------------------------------------------------
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
\begin{document}
%----------------------------------------------------------------------------------------
% PDF TITLE PAGE (NOT INCLUDED FOR MWE)
%----------------------------------------------------------------------------------------
%-----------------------------PDF PAGE---------------------------------
\pagenumbering{roman}
%----------------------------------------------------------------------------------------
% STATEMENT OF ORIGINALITY
%----------------------------------------------------------------------------------------
\section*{\LARGE\center{Statement of Originality\markboth{}{Statement of Originality}}}
\addcontentsline{toc}{chapter}{{Statement of Originality}}
\thispagestyle{fancy}
\newpage
%----------------------------------------------------------------------------------------
% ACKNOWLEDGEMENTS
%----------------------------------------------------------------------------------------
\section*{\LARGE\center{Acknowledgements (optional)\markboth{}{Acknowledgements}}}
\addcontentsline{toc}{chapter}{{Acknowledgements}}
\thispagestyle{fancy}
\newpage
%----------------------------------------------------------------------------------------
% ABSTRACT
%----------------------------------------------------------------------------------------
\section*{\LARGE\center{Abstract\markboth{}{Abstract}}}
\addcontentsline{toc}{chapter}{{Abstract}}
\thispagestyle{fancy}
\newpage
%----------------------------------------------------------------------------------------
% ACRONYMS (OPTIONAL)
%----------------------------------------------------------------------------------------
\section*{\LARGE\center{Acronyms (optional)\markboth{}{Acronyms}}}
\addcontentsline{toc}{chapter}{{Acronyms}}
\thispagestyle{fancy}
\newpage
%----------------------------------------------------------------------------------------
% SYMBOLS (OPTIONAL)
%----------------------------------------------------------------------------------------
\section*{\LARGE\center{Symbols (optional)\markboth{}{Symbols}}}
\addcontentsline{toc}{chapter}{{Symbols}}
\thispagestyle{fancy}
\newpage
%----------------------------------------------------------------------------------------
% TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
\begin{center}
\hypersetup{linkcolor=black} % Make Links Black
\vspace*{-40pt}
\tableofcontents\thispagestyle{fancy}\markboth{}{Table of Contents}
\addcontentsline{toc}{chapter}{Table of Contents}
\newpage
\vspace*{-40pt}
\listoffigures\thispagestyle{fancy}\markboth{}{}
\addcontentsline{toc}{chapter}{List of Figures}
\newpage
\vspace*{-40pt}
\listoftables\thispagestyle{fancy}\markboth{}{}
\addcontentsline{toc}{chapter}{List of Tables}
\end{center}
\newpage
\pagenumbering{arabic}
%----------------------------------------------------------------------------------------
% MAIN TEXT (CHAPTERS)
%----------------------------------------------------------------------------------------
\chapter{Introduction}
\section{Introduction}\thispagestyle{fancy}
\Blindtext
\blindtext
\chapter{Literature Review}\thispagestyle{fancy}
\section{Background/Problem}
\blindtext
\section{Analysis..}
\Blindtext
\Blindtext
\chapter{Methodology}\thispagestyle{fancy}
\section{Procedure}
\blindtext\\
\blindtext \\
\blindtext\\
\blindtext
\section{Simulation?}
\blindtext\\
\blindtext \\
\blindtext
\chapter{Results and Discussion}\thispagestyle{fancy}
\section{Results Verification?}
\Blindtext
\chapter{Future Developments}\thispagestyle{fancy}
\section{Recommendations for Future Work}
\blindtext\\
\blindtext
\chapter{Conclusion}\thispagestyle{fancy}
\section{Conclusion}
\blindtext
%----------------------------------------------------------------------------------------
% APPENDIX
%----------------------------------------------------------------------------------------
\begin{appendix}
\chapter{Example 1}\thispagestyle{fancy}
\section{Testing}
\Blindtext
\chapter{Example 2}\thispagestyle{fancy}
\section{Extra}
\blindtext
\end{appendix}
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY/REFERENCES
%----------------------------------------------------------------------------------------
%-------------------------------REFS-----------------------------------
\end{document}
抱歉,这个帖子太长了,我只是觉得我应该尝试彻底解释我的问题和我想要的结果。我目前正在使用该fancyhdr
软件包,但如果您认为我应该使用 KOMA Script 等效程序,请随时发表评论,告诉我应该如何使用它(我以前没有使用过 KOMA Script)。
谢谢。
答案1
如果您愿意使用类(和类memoir
的超集),那么您可以获得所需的页眉/页脚。我知道它看起来很复杂,但可以让您定义许多页面样式以及它们的使用位置。book
report
memoir
在我看来,您需要几种不同的页面样式;对于目录(大概还有 LoT 和 LoF),也许用于标题页,对于章节标题页,对于一般文档页面,也许用于索引或参考书目。
以下 MWE 为 ToC 和 LoT、章节标题页(包括附录)和一般普通页面提供页面样式。
% headersprob.tex SE 562212
\documentclass{memoir}
\usepackage{lipsum}
\usepackage{comment}
% macro for details of the footer style
\newcommand{\enelf}[1]{%
\makeevenfoot{#1}{\small \parbox[t]{1in}{ENEL895 \\ Version 1.0}}{\small \thepage}{\small \today}
\makeoddfoot{#1}{\small \parbox[t]{1in}{ENEL895 \\ Version 1.0}}{\small \thepage}{\small \today}
\makefootrule{#1}{\textwidth}{1pt}{5pt}
}
\makepagestyle{ENELfoot}
\enelf{ENELfoot}
% pagestle for the ToC
\makepagestyle{ENELtoc}
\makeevenhead{ENELtoc}{}{}{Table of Contents}
\makeoddhead{ENELtoc}{}{}{Table of Contents}
\makeheadrule{ENELtoc}{\textwidth}{1pt}
\enelf{ENELtoc}
% pagestyle of the LoT
\makepagestyle{ENELlot}
\makeevenhead{ENELlot}{}{}{List of Tables}
\makeoddhead{ENELlot}{}{}{List of Tables}
\makeheadrule{ENELlot}{\textwidth}{1pt}
\enelf{ENELlot}
% pagestyle for chapter pages
\makepagestyle{chapter}
\enelf{chapter}
% don't uppercase chapter and section titles in headers
% (regular definition uses \MakeUppercase for titles)
\makeatletter
\renewcommand*{\chaptermark}[1]{%
\markboth{\ifnum\c@secnumdepth > \m@ne
\if@mainmatter
\@chapapp\
\thechapter \ %
\fi
\fi
#1}{}}
\renewcommand*{\sectionmark}[1]{%
\markright{\ifnum\c@secnumdepth > \z@
\thesection \ %
\fi
#1}}
\makeatother
% The page style for the bulk of the document
\makepagestyle{ENELmain}
\makeevenhead{ENELmain}{\leftmark}{}{\rightmark}
\makeoddhead{ENELmain}{\leftmark}{}{\rightmark}
\enelf{ENELmain}
\begin{document}
\pagestyle{ENELfoot}
\frontmatter
\pagestyle{ENELtoc}
\copypagestyle{chapter}{ENELtoc} % the first page of the ToC uses the chapter pagestyle
\tableofcontents
\clearpage
\pagestyle{ENELlot}
\copypagestyle{chapter}{ENELlot} % the first page of the LoT uses the chapter page style
\listoftables
\mainmatter
% set the general page style
\pagestyle{ENELmain}
% first page of a chapter uses the chapter page style, so set it to be just the footer
\copypagestyle{chapter}{ENELfoot}
\chapter{One}
\lipsum
\section{A section}
\begin{table}
\centering
TABULATION
\caption{A table}
\end{table}
\lipsum
\addtocontents{toc}{\newpage} % make sure the ToC is more that one page
\section{Another section}
\lipsum
\appendix
\chapter{App}
\lipsum
\section{In appendix}
\lipsum
\end{document}
阅读文档(> texdoc memoir
第 7 章)以了解更多信息。
答案2
正如 fancyhdr 软件包文档指出的,命令\chapter
问题\thispagestyle{plain}
。
我相信\tableofcontents
也是这样。因此可能需要
重新定义页面样式。 您可以通过添加到序言中来做到这一点,这将页面样式设置为页面样式,但页眉为空。 这会导致在引入新章节的页面上没有页眉,但有页脚。每当您创建新章节时 ,都不要忘记删除。plain
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrule}{}}
plain
fancy
\thispagestyle{fancy}
关于标题未显示在所有页面上的问题,问题似乎出在定义\captionmark
和上\sectionmark
。
我发现似乎有效的方法是删除这些重新定义并添加\nouppercase
两个标题的定义,从而导致
\fancyhead[L]{\nouppercase\leftmark} % SECTION NAME-FIRST SECTION/PREVIOUS SECTION
\fancyhead[R]{\nouppercase\rightmark} % CHAPTER NAME