
我目前正在嘗試為專案報告建立文件。我在處理頁首和頁尾時遇到困難。
我想要每頁的頁腳頁腳應如下圖所示。
為了實現這個頁腳,我目前正在使用該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 頁上,第一頁只有頁腳的頁碼,而第二頁有正確的頁首和頁尾。
標題是變得複雜的地方。對於標題,我需要所有頭條新聞(第一章之前的所有內容)章節標題於右邊標題和字母大小寫應與標題大小寫完全相同(即不大寫和不斜體)。 TOC 標題(如上所示)是我的意思的一個例子。至於章節,我希望第一章頁面沒有頁眉,只有上面指定的頁腳。對於本章的其餘頁面,我想要標題左側的章節(格式:章節# - 章節名稱)和右側的部分(格式:# 部分名稱)。
頁首和頁尾本章的剩餘頁數應該如下圖所示(忽略我已經顯示了本章第一頁的事實)。
我在標題方面遇到的另一個困難是附錄標題有章節 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