我编写了自己的论文 .cls 文件,但不确定如何将章节页码置于右上角。我相信基类是report
而不是article
。我使用示例模板开始我的工作。
这是我的 .cls 文件中指定页码位置的具体部分
%----------------------------------------------------------------------%
%% Specify frontmatter, mainmatter, and backmatter
%----------------------------------------------------------------------%
\RequirePackage{fancyhdr}
\newcommand\frontmatter{%
\cleardoublepage
\pagenumbering{roman}}
\newcommand\mainmatter{%
\addtocontents{toc}{\vspace{1em}\noindent{\bf\uppercase{Chapters}}\hfill\par} % Add the word "Chapters" in the TOC as per University requirements
\cleardoublepage
\pagestyle{fancy}
\fancyhf{} % clear the fancy header
\lhead{} % nothing in the left corner
\rhead{\thepage} % page number in the top right corner
\renewcommand{\headrulewidth}{0pt} % hide the line at the top of the fancy header
\pagenumbering{arabic}
\doublespacing
}
\newcommand\backmatter{%
\if@openright
\cleardoublepage
\else
\clearpage
\fi
% \@mainmatterfalse
}
如果需要的话,我已经包含了整个 .cls 文件以供参考。
%----------------------------------------------------------------------%
% University of Utah LaTeX Updated Thesis Template
% Christopher Creveling
% 12-7-2020
% Department of Mechanical Engineering
%----------------------------------------------------------------------%
%----------------------------------------------------------------------%
% Identification
%----------------------------------------------------------------------%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{MastersDoctoralThesis}[12/7/20 MastersDoctoralThesis]
%----------------------------------------------------------------------%
% Report options
%----------------------------------------------------------------------%
\DeclareOption{11pt}{
\PassOptionsToClass{\CurrentOption}{article} % book report
}
%% Execute default options
\ExecuteOptions{11pt}
%% Process given options
\ProcessOptions\relax
%% Load base
\LoadClass[letterpaper]{report}
\RequirePackage[utf8]{inputenc} % Required for inputting international characters
\RequirePackage[T1]{fontenc} % Output font encoding for international characters
\RequirePackage{amsmath}
\RequirePackage{amssymb}
\RequirePackage{mathpazo} % Use the Palatino font by default
\RequirePackage{setspace} % Single/Doublespacing options
\RequirePackage{etoolbox}
\AtBeginEnvironment{tabular}{\singlespacing}% Single spacing in tabular environment
\RequirePackage{subfiles} % Allows for individual components to be created
\RequirePackage{lipsum} % random paragraphs # 66 & 75 are the shortest (4 lines each)
% Required for tables that span multiple pages (used in the symbols,
% abbreviations and physical constants pages)
\RequirePackage{longtable}
\RequirePackage{booktabs} % Required for better table rules
%----------------------------------------------------------------------%
% Graphicsx package with option to turn on/off images for fast compiling
%----------------------------------------------------------------------%
%\RequirePackage{etoolbox} % When using ubuntu, this needs to be before tabular
\newbool{graphicDraft} % Option to turn graphics on/off
\DeclareOption{graphicFinal}{\boolfalse{graphicDraft}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\baseclass}}
\ProcessOptions\relax
%\RequirePackage[draft]{graphicx}
\ifbool{graphicDraft}
{\RequirePackage[draft]{graphicx}}
{\RequirePackage[final]{graphicx}}
\RequirePackage{subcaption} % package to create subfigure
\RequirePackage{animate} % Animating stacks of images (pdf, png, etc.)
\RequirePackage{pdfpages} % Attach PDFs in the document
%----------------------------------------------------------------------%
% single spacing for all captions
%----------------------------------------------------------------------%
\RequirePackage[font=singlespacing]{caption}
%----------------------------------------------------------------------%
% float package
%----------------------------------------------------------------------%
% Allows figures and tables to be set in place "[H]"
\RequirePackage{float}
%----------------------------------------------------------------------%
% TodoNotes package
%----------------------------------------------------------------------%
\RequirePackage{todonotes} % to do notes
%----------------------------------------------------------------------%
% Geometry of the document
%----------------------------------------------------------------------%
\RequirePackage{geometry}
\geometry{
paper = letterpaper, % Change to letterpaper for US letter
inner = 1.25in, % Inner margin
outer = 1.25in, % Outer margin
bindingoffset = 0in, % Binding offset
top = 1in, % Top margin
bottom = 1in, % Bottom margin
head = 2in, % header height % University guideline
showframe, % Uncomment to show how the type block is set on the page
}
%----------------------------------------------------------------------%
% COLORS
%----------------------------------------------------------------------%
\RequirePackage{xcolor} % Required for specifying custom colors
\definecolor{BLACK}{HTML}{000000}
\definecolor{UOFURED}{HTML}{CC0000}
\definecolor{midnightBlue}{HTML}{145680} % midnight blue
\definecolor{darkBrown}{HTML}{654321} % Dark brown
\definecolor{arsenic}{HTML}{3B444B}
%----------------------------------------------------------------------%
% Chapter heading font size
%----------------------------------------------------------------------%
\RequirePackage{sectsty}
\chapternumberfont{\normalsize}
\chaptertitlefont{\normalsize}
%----------------------------------------------------------------------%
% Title spacing
%----------------------------------------------------------------------%
\RequirePackage{titlesec} % Adjust title headers
% Force Heading space after chapter/section/subsection/subsubsections to be the same
\titlespacing{\chapter}{0pt}{2em}{2em}[0pt] % two lines of text before and after "2em"
\titlespacing{\section}{0pt}{2em}{2em}[0pt] % two lines of text before and after "2em"
\titlespacing{\subsection}{0pt}{2em}{2em}[0pt] % two lines of text before and after "2em"
\titlespacing{\subsubsection}{0pt}{2em}{2em}[0pt] % two lines of text before and after "2em"
% Single spaced headers
\titleformat{\chapter} % command
[display] % shape
{\color{UOFURED}\centering\normalfont\Large\bfseries\doublespacing}
{\MakeUppercase{\chaptertitlename} \Large\thechapter}
{0pt} % separations
{\MakeUppercase} % before
[] % After (leave blank)
%\titleformat{\chapter}[display]{\centering\normalfont\huge\bfseries\singlespacing}{\chaptertitlename\ \thechapter}{40pt}{\huge}
\titleformat{\section}{\centering\singlespacing\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\centering\singlespacing\normalfont\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}{\centering\singlespacing\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}
%----------------------------------------------------------------------%
% References
%----------------------------------------------------------------------%
% `final' to prevent disabling and reference links to be split
% up on different lines
\RequirePackage[final]{microtype}
\RequirePackage[defernums=true,
hyperref,
backref,
backend=biber,
style=ieee,
natbib=true,
refsegment=chapter,
block=space
]{biblatex} % Use the bibtex backend, biber
\setlength\bibitemsep{1.5\itemsep} % Spacing between items in bilbiography
% Define typesetting of references heading
\defbibheading{references}[References]{%
\section{#1}% Add section so that the table of contents adds the chapter references
\markboth{#1}{#1}%
\singlespacing
}
%----------------------------------------------------------------------%
% Final Bibliography
% Add type=book, article, online, thesis for specific references
%----------------------------------------------------------------------%
\def\finalBibliography{
{\singlespacing
\printbibliography[heading=bibintoc, title={\uppercase{Bibliography}}] % Whole
}
}
%----------------------------------------------------------------------%
% Hyperlinks
%----------------------------------------------------------------------%
\RequirePackage{hyperref}
\hypersetup{pdfpagemode={UseOutlines},
bookmarksopen=true,
bookmarksopenlevel=0,
hypertexnames=true, % reference roman numerals and numeric pages
colorlinks=true,% Set to false to disable coloring links
citecolor=darkBrown,% The color of citations
linktoc=all,
linkcolor=UOFURED,% The color of references to document elements (sections, figures, etc)
urlcolor=midnightBlue,% The color of hyperlinks (URLs)
pdfstartview={FitV},
unicode,
breaklinks=true, % split up links
}
\RequirePackage{doi} % DOI field in references
\RequirePackage{url} % URL allowed to split up
\RequirePackage[capitalise]{cleveref} % Needs to be loaded after hyperref
%----------------------------------------------------------------------%
% % Adjust table of contents, list of figures, list of tables specifically
%----------------------------------------------------------------------%
\RequirePackage[titles]{tocloft} % Treat the headers as titles
\renewcommand{\cftchapdotsep}{\cftdotsep} % Puts dots after chapter entries
\renewcommand{\contentsname}{\color{UOFURED}\hfill \Large CONTENTS \hfill} % Normal font
\renewcommand{\listfigurename}{\color{UOFURED}\hfill \Large LIST OF FIGURES \hfill} % Normal font
\renewcommand{\listtablename}{\color{UOFURED}\hfill \Large LIST OF TABLES \hfill} % Normal font
\renewcommand\cftchapafterpnum{\vskip2pt} % Spacing of the TOC items
\renewcommand\cftsecafterpnum{\vskip2pt} % Spacing of the TOC items
\renewcommand\cftsubsecafterpnum{\vskip2pt} % Spacing of the TOC items
\setlength{\cfttabindent}{0em} % Force LOT to be the correct width
\setlength{\cftfigindent}{0em} % Force LOF to be the correct width
%%----------------------------------------------------------------------%
% Algorithm writing
%----------------------------------------------------------------------%
\RequirePackage{algpseudocode}
\RequirePackage{algorithm}
%----------------------------------------------------------------------%
%% Thesis Title Page
%----------------------------------------------------------------------%
\def\thesistype#1{\gdef\@thesistype{#1}} % thesis or dissertation
\def\degreeAchieved#1{\gdef\@degreeAchieved{#1}} % exact degree being gotten
\def\department#1{\gdef\@department{#1}} % Department
\def\departmentLink#1{\gdef\@departmentLink{#1}} % Department
\def\submitdate#1{\gdef\@submitdate{#1}} % Submission date.
\newcommand\skiplines[1]{\vspace{#1\baselineskip}} % function for skipping n number of lines
\newcommand\thesisTitle{
{
%\newpage
\thispagestyle{empty}% Doesn't count in table of contents
\begin{minipage}[c]{\textwidth}
%\chapter*{\color{BLACK}\uppercase{\@title}} % This doesn't work
\vspace{1in}
\begin{center}
\begin{spacing}{2} % university requirement
{\doublespacing\Large\bfseries\MakeUppercase{\@title}}\\
\end{spacing}
\large
\skiplines{4} % university requirement
\begin{spacing}{2} % university requirement
by \\
\@author \\
\end{spacing}
\skiplines{4} % university requirement
A \@thesistype ~submitted to the faculty of\\
The University of Utah\\
in partial fulfillment of the requirements for the degree of \\
\skiplines{4} % university requirement
{\@degreeAchieved}\\
\skiplines{4} % university requirement
\begin{spacing}{2} % university requirement
\href{\@departmentLink}{\@department}\\
\href{http://utah.edu}{The University of Utah}\\ %
\@submitdate
\end{spacing}
\end{center}
\end{minipage}
\clearpage
}
}
%----------------------------------------------------------------------%
% The format of the title page is laid out in elaborate detail.
% Fixes by Nelson Beebe Nov 1992:
% The title is centered in a vbox of fixed height so that it can
% have up to 9 lines. Version 1.3 and earlier used explicit blank lines,
% which caused spill of the entire titlepage onto a second
% numbered page if a multiline title was specified.
%----------------------------------------------------------------------%
\newlength{\minilength}
\setlength{\minilength}{.95\textwidth}
%
\def\UofUtitlepageNinetyThree{
\thispagestyle{empty}%
\noindent\hspace{1em}%
\begin{minipage}[c]{\minilength}%
\begin{center}%
\vbox to 9\baselineskip {%
\HFmainhead\bfseries
\vss
\begin{center}
\@title
\end{center}
\vss
}%
\mbox{} \\
by\\
\mbox{} \\
\@author \\
\vbox to 15\baselineskip
{
\vss
A \@thesistype ~submitted to the faculty of\\
The University of Utah\\
in partial fulfillment of the requirements for the degree of
\vss
}
\@degree \\
\vskip 7\baselineskip
\expandafter{\@department}\\
\mbox{} \\
The University of Utah \\
\mbox{} \\
\@submitdate%
\end{center}%
\end{minipage}%
\ifnoisy \typeout{Title.} \fi
\newpage% Added 1995 by GBG; see Eric Eide notes.
}
%----------------------------------------------------------------------%
%% Copyright page
%----------------------------------------------------------------------%
\def\copyrightyear#1{\gdef\@copyrightyear{#1}} % Copyright year
\newcommand\copyrightpage{
{\newpage
\thispagestyle{empty}% Doesn't count in table of contents
%\phantomsection
%\pdfbookmark{Copyright year}{toc} % Add bookmark to PDF
\topskip0pt
\vspace*{\fill}
\noindent
\begin{minipage}[c]{\textwidth}%
\begin{center}%
Copyright \copyright\ \@author\ \@copyrightyear \\
\skiplines{1} % university requirement
All Rights Reserved
\end{center}%
\end{minipage}%
\vspace*{\fill}
\newpage% Added 1995 by GBG; see Eric Eide notes.
}
}
%----------------------------------------------------------------------%
%% The committee approval page is highly constrained. Its format is not
%% exactly identical to the preprinted ones.
%----------------------------------------------------------------------%
% Define committee members
\def\committeeChair#1{\gdef\@committeeChair{#1}} % Committee chair #1
\def\advisorTitle#1{\gdef\@\advisorTitle{#1}} % Advisor title (not really used)
\def\committeeMemberII#1{\gdef\@committeeMemberII{#1}} % Committee chair #2
\def\committeeMemberIII#1{\gdef\@committeeMemberIII{#1}} % Committee chair #3
\def\committeeMemberIIII#1{\gdef\@committeeMemberIIII{#1}} % Committee chair #4
\def\committeeMemberIIIII#1{\gdef\@committeeMemberIIIII{#1}} % Committee chair #5
% Define Graduate Dean & Department Chair
\def\graduateDean#1{\gdef\@graduateDean{#1}} % Graduate Dean
\def\departmentChair#1{\gdef\@departmentChair{#1}} % Department Chair
\def\departmentChairTitle#1{\gdef\@departmentChairTitle{#1}} % Department Chair Title
\def\deptmentCollegeSchool#1{\gdef\@deptmentCollegeSchool{#1}} % Department/College/School
% Define approval dates
\def\approvaldepartment#1{\gdef\@approvaldepartment{#1}}
\def\chairDateApproved#1{\gdef\@chairDateApproved{#1}}
\def\committeeMemberIIDateApproved#1{\gdef\@committeeMemberIIDateApproved{#1}}
\def\committeeMemberIIIDateApproved#1{\gdef\@committeeMemberIIIDateApproved{#1}}
\def\committeeMemberIIIIDateApproved#1{\gdef\@committeeMemberIIIIDateApproved{#1}}
\def\committeeMemberIIIIIDateApproved#1{\gdef\@committeeMemberIIIIIDateApproved{#1}}
\def\bfunderline#1{\underline{\kern 1in \textbf{#1}\kern 1in}}
\RequirePackage{tabularx} % pagewidth tables
\RequirePackage{array} % Specify width of tables
\RequirePackage{ragged2e} % Allows for justification of sections
\long \def \dissertationapproval{%
\newpage
%
\thispagestyle{empty}% Doesn't count in table of contents
%\phantomsection
%\pdfbookmark{Dissertation Approval}{toc} % Add bookmark to PDF
\begin{center}
\textbf{\Large The University of Utah Graduate School} \\
\skiplines{2} % university requirement
\textbf{\Large STATEMENT OF DISSERTATION APPROVAL}
\skiplines{2} % university requirement
\end{center}
%
\justify
\begin{doublespace}
The dissertation of\hspace{1in}\bfunderline{\@author} \\
\skiplines{2} % university requirement
has been approved by the following supervisory committee members:
\begin{center}
\begin{table}[htbp]
\centering
\begin{tabular}{>{\centering\arraybackslash}p{0.6\textwidth}p{0.1\textwidth}>{\centering\arraybackslash}p{0.2\textwidth}}
\bfseries{\@committeeChair} & \multicolumn{1}{l}{ , Chair} & \multicolumn{1}{c}{\bfseries{\@chairDateApproved}} \\
\cmidrule{1-1}\cmidrule{3-3} & & \tiny{Date Approved} \\
& & \\ % add extra row between the committee members
\bfseries{\@committeeMemberII} & \multicolumn{1}{l}{ , Member} & \multicolumn{1}{c}{\bfseries{\@committeeMemberIIDateApproved}} \\
\cmidrule{1-1}\cmidrule{3-3} & & \tiny{Date Approved} \\
& & \\ % add extra row between the committee members
\bfseries{\@committeeMemberIII} & \multicolumn{1}{l}{ , Member} & \multicolumn{1}{c}{\bfseries{\@committeeMemberIIIDateApproved}} \\
\cmidrule{1-1}\cmidrule{3-3} & & \tiny{Date Approved} \\
& & \\ % add extra row between the committee members
\bfseries{\@committeeMemberIIII} & \multicolumn{1}{l}{ , Member} & \multicolumn{1}{c}{\bfseries{\@committeeMemberIIIIDateApproved}} \\
\cmidrule{1-1}\cmidrule{3-3} & & \tiny{Date Approved} \\
& & \\ % add extra row between the committee members
\bfseries{\@committeeMemberIIIII} & \multicolumn{1}{l}{ , Member} & \multicolumn{1}{c}{\bfseries{\@committeeMemberIIIIIDateApproved}} \\
\cmidrule{1-1}\cmidrule{3-3} & & \tiny{Date Approved} \\
\end{tabular}%
\end{table}%
\end{center}
\justify
and by \hspace{1in}\bfunderline{\@departmentChair}, {\@departmentChairTitle} of \\
the {\@deptmentCollegeSchool} of \hspace{1in}\bfunderline{\@approvaldepartment} \\
and by \bfunderline{\@graduateDean}, Dean of The Graduate School.\\
\end{doublespace}
}
%----------------------------------------------------------------------%
%% Abstract
%----------------------------------------------------------------------%
\def\abstractString#1{\gdef\@abstractString{#1}} % Abstract
\newcommand\abstractpage{
{\newpage
\chapter*{Abstract}
\setcounter{page}{3} % manually set to page iii
\addcontentsline{toc}{chapter}{\uppercase{Abstract}}
\hspace{\parindent}
\begin{doublespace}
\@abstractString
\end{doublespace}
}
}
%----------------------------------------------------------------------%
% Dedication page
%----------------------------------------------------------------------%
\def\dedication#1{\gdef\@dedication{#1}} % Dedication
\newcommand\dedicationpage{
{\newpage
\clearpage\thispagestyle{empty}\addtocounter{page}{-1} % Don't include in page count
\topskip0pt
\vspace*{\fill}
\noindent
\begin{minipage}[c]{.95\textwidth}%
\begin{center}%
\@dedication
\end{center}%
\end{minipage}%
\vspace*{\fill}
}
}
%----------------------------------------------------------------------%
% Frontispiece page
%----------------------------------------------------------------------%
\def\frontispiece#1{\gdef\@frontispiece{#1}} % Frontispiece
\newcommand\frontispiecePage{
{\newpage
\clearpage\thispagestyle{empty} % Don't display the page number but still add to the total count
\topskip0pt
\vspace*{\fill}
\noindent
\begin{minipage}[c]{\textwidth}%
\centering
\includegraphics[width=\textwidth]{{\@frontispiece}}
\end{minipage}%
\vspace*{\fill}
}
}
%----------------------------------------------------------------------%
% Epigraph page (Inspirational quote)
%----------------------------------------------------------------------%
\RequirePackage{epigraph} % epigraph package
\def\epigraphQuote#1{\gdef\@epigraphQuote{#1}} % Epigraph quote
\def\epigraphAuthor#1{\gdef\@epigraphAuthor{#1}} % Epigraph author
%\setlength{\epigraphwidth}{0.6\textwidth} % Width of epigraph
\newcommand\epigraphPage{
{\newpage
\clearpage\thispagestyle{empty} % Don't display the page number but still add to the total count
\topskip0pt
\vspace*{\fill}
\noindent
\begin{minipage}[c]{\textwidth}%
\centering
\epigraph{\Large{\@epigraphQuote}}{---{\@epigraphAuthor}}
\end{minipage}%
\vspace*{\fill}
}
}
%----------------------------------------------------------------------%
%% Specify frontmatter, mainmatter, and backmatter
%----------------------------------------------------------------------%
\RequirePackage{fancyhdr}
\newcommand\frontmatter{%
\cleardoublepage
\pagenumbering{roman}}
\newcommand\mainmatter{%
\addtocontents{toc}{\vspace{1em}\noindent{\bf\uppercase{Chapters}}\hfill\par} % Add the word "Chapters" in the TOC as per University requirements
\cleardoublepage
\pagestyle{fancy}
\fancyhf{} % clear the fancy header
\lhead{} % nothing in the left corner
\rhead{\thepage} % page number in the top right corner
\renewcommand{\headrulewidth}{0pt} % hide the line at the top of the fancy header
\pagenumbering{arabic}
\doublespacing
}
\newcommand\backmatter{%
\if@openright
\cleardoublepage
\else
\clearpage
\fi
% \@mainmatterfalse
}
%----------------------------------------------------------------------%
%% Custom table of contents
%----------------------------------------------------------------------%
\renewcommand\cftfigafterpnum{\vskip5pt\par} % list of figure spacing
\renewcommand\cfttabafterpnum{\vskip5pt\par} % list of table spacing
\newcommand\tableOfContents{
{
\hypersetup{linkcolor=blue} % Change color if you want something different
\clearpage
\pdfbookmark{Table of Contents}{toc} % Add bookmark to PDF
\tableofcontents % Prints the main table of contents
\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{\uppercase{List of Figures}} % Adds to TOC
\listoffigures % Prints the list of figures
\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{\uppercase{List of Tables}} % Adds to TOC
\listoftables % Prints the list of tables
}
}
% turn off the error for \uppercase in chapter titles
\pdfstringdefDisableCommands{\let\uppercase\relax}
%----------------------------------------------------------------------%
%% % Mendeley bib file URL issue fix
%----------------------------------------------------------------------%
\DeclareSourcemap{
\maps{
\map{ % Replaces '{\_}', '{_}' or '\_' with just '_'
\step[fieldsource=url,
match=\regexp{\{\\\_\}|\{\_\}|\\\_},
replace=\regexp{\_}]
}
\map{ % Replaces '{'$\sim$'}', '$\sim$' or '{~}' with just '~'
\step[fieldsource=url,
match=\regexp{\{\$\\sim\$\}|\{\~\}|\$\\sim\$},
replace=\regexp{\~}]
}
\map{ % Replaces '{\$}'
\step[fieldsource=url,
match=\regexp{\{\\\x{26}\}},
replace=\regexp{\x{26}}]
}
}
}
%----------------------------------------------------------------------%
%% % Prevent Orphans and Widows (lines begining at the bottom/top of a page)
%----------------------------------------------------------------------%
\RequirePackage[defaultlines=2,all]{nowidow}
\endinput
% Christopher Creveling
当我定义一个章节时:
\chapter{The first}
它将页码添加到页脚的中心。当我创建新的章节和子章节时,所有其他页面都是正确的。
首页 [1]:https://i.stack.imgur.com/7VUP7.png 第二页[2]:https://i.stack.imgur.com/H8ECx.png
提前致谢,因为我不确定如何解决这个问题。
答案1
基本上,这将是
\fancypagestyle{plain}{%
\renewcommand{\headrulewidth}{0pt}%
\fancyhf{}%
\fancyhead[R]{\thepage}%
}