
這個問題可能已經被問過,但我似乎找不到答案或弄清楚這一點。
我正在使用muthesis
撰寫論文的範本。這在偶數頁上給出章節標題為“第 x 章。章節名稱”,但在奇數頁上給出章節名稱和編號。
我怎麼能讓它在所有頁面上給我「第x章。章節名稱」(加上目前的頁碼)。
我懷疑這可以用 fancyhdr 來完成,但我不知道該怎麼做。
請注意,我使用的是雙面文檔。
希望有人可以幫忙!
這是一個 MWE:
\documentclass[11pt,PhD,twoside]{muthesis}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{todonotes}
\usepackage{amsmath}
\usepackage{amstext}
\usepackage{paralist}
\usepackage{enumitem}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage{stackengine}
\usepackage[aboveskip=2pt]{subcaption} % aboveskipchanges spacing beten caption and figure
\usepackage{caption}
\captionsetup[subfigure] {justification=justified,singlelinecheck=false} %%% alignment of subfigure captions
\usepackage{pgfplotstable}
\usepackage[UKenglish]{datetime}
\usepackage{parskip}
\usepackage{booktabs}
\usepackage{colortbl}
\pgfplotstableset{col sep=comma}
\usepackage[none]{hyphenat}
\usepackage{subfig}
\usepackage{multirow}
\usepackage{lscape}
\usepackage{cite}
% for references\
\usepackage{natbib}
%\setlength{\bibhang}{5em}
%%%%%% Make font smaller
\renewcommand{\bibfont}{\normalfont\small}
%%% to sort out issues with urls
\usepackage[hyperindex,breaklinks]{hyperref}
\usepackage{cite}
\usepackage{graphics}
\usepackage{amstext}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{booktabs}
\usepackage{url} % typeset URLs reasonably
\usepackage{listings}
%%%%%% section size
\usepackage[]{titlesec}
\titleformat{\section}
{\normalfont\fontsize{13}{15}\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsubsection}{1em}{}
\titleformat{\subsubsubsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsubsubsection}{1em}{}
%%%% Number of sections that are numbered increase
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
%%%%%%%%%%%%%%%
\begin{document}
\title{A thesis}
\author{AN Author}
\school{School of}
\faculty{Faculty}
\def\wordcount{57103}
\beforeabstract
\section*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
\sloppy
\begin{spacing}{1.0}
\fontsize{12}{12}\normalfont
abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract
\end{spacing}
\afterabstract
\prefacesection{Acknowledgements}
I would like to thank......
\afterpreface
\chapter{Introduction}
\section{Background}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background2}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background3}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\end{document}
答案1
有幾件事:
使用此類的唯一原因是您需要滿足它實現的機構要求。如果是這種情況,更改佈局將導致您的作品被視為不可接受。
如果不是這種情況,最好建議您使用不同的類別。這非常明確地表明它違反了良好排版的規則。必須如此。機構要求要求較差的排版。
就目前情況而言,您的程式碼編譯時不會出錯。這與下一點密切相關。
你的序言一團糟。這使得確保一致性變得更加困難,增加了套件發生衝突的機會,幾乎肯定會出現奇怪、神秘的問題,並且在問題不可避免地發生時更難以診斷問題。
- 不要多次加載包。
- 特別是,不要載入具有不同選項的套件。
- 不要載入多個旨在以不同方式格式化相同文件元素的套件,例如
enumitem
和paralist
;subcaption
和subfig
。 - 不要加載多餘的包,
url
例如hyperref
;graphics
也graphicx
。 - 請注意重要的訂購要求,例如
hyperref
應延遲裝載。 - 根據需要使用盡可能多的包,並且不要超過您需要的數量。
\sloppy
除非你的機構明確要求這種排版怪物,否則不要排版你的整篇論文。 (這不太可能:我從未聽說過他們需要這個,儘管他們經常需要其他類型的印刷怪物。)
在回答特定問題時,\afterpreface
將頁面樣式設定為headings
。重新定義該命令,將其設定為fancy
允許fancyhdr
設定生效:
下面是帶有一些更具體註解的完整程式碼。我嘗試將提供類似功能的套件分組在一起,以便更輕鬆地查看您需要什麼和不需要什麼。如果您不知道為什麼要使用包,請將其註解掉,看看這是否會破壞您的編譯。如果沒有,您可能可以不用它。
不過,我已經添加了強烈建議的字體fontenc
編碼T1
,並且還可以為您提供可縮放的 type1 字體。
\documentclass[11pt,PhD,twoside]{muthesis}
\usepackage[T1]{fontenc}% recommended
\usepackage{textcomp}
\usepackage{todonotes}
\usepackage{amsmath}
\usepackage{amstext}
% \usepackage{paralist}% enumitem provides similar functionality - stick to one interface
\usepackage{enumitem}
% tables
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{booktabs}
% captions and floats
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage[aboveskip=2pt]{subcaption} % aboveskipchanges spacing beten caption and figure
\captionsetup[subfigure] {justification=justified,singlelinecheck=false} %%% alignment of subfigure captions
% \usepackage{subfig}% if you are using subcaption, don't try to use subfig, too - this way lies madness
\usepackage{stackengine}
% colour, graphics, diagrams
\PassOptionsToPackage{table}{xcolor}
\usepackage{graphicx}% don't load graphics as well - this covers it all already
\usepackage{pgfplotstable}
\pgfplotstableset{col sep=comma}
\usepackage[UKenglish]{datetime}
\usepackage{parskip}
\usepackage[none]{hyphenat}
\usepackage{lscape}
% for references
% \usepackage{cite}% do you really want this as well as natbib? they are likely to fight!
\usepackage{natbib}
%\setlength{\bibhang}{5em}
\renewcommand{\bibfont}{\normalfont\small}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{listings}
\usepackage[]{titlesec}
\usepackage{fancyhdr}
% to sort out issues with urls
% for latex
% \usepackage[hyperindex,breaklinks]{hyperref}% load late: loads url - no need to load separately
% for pdflatex, lualatex or xelatex
\usepackage[hyperindex]{hyperref}% load late: loads url - no need to load separately
\titleformat{\section}
{\normalfont\fontsize{13}{15}\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsubsection}{1em}{}
\titleformat{\subsubsubsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsubsubsection}{1em}{}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\def\afterpreface{\newpage
\pagestyle{fancy}}
\pagestyle{fancy}
\fancyhf{}
\renewcommand*\headrulewidth{0pt}
\fancyhf[leh,roh]{\thepage}
\fancyhf[loh,reh]{\slshape\leftmark}
\begin{document}
\title{A thesis}
\author{AN Author}
\school{School of}
\faculty{Faculty}
\def\wordcount{57103}
\beforeabstract
\section*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
% \sloppy% don't do this: It applies \sloppy to the rest of your document which is almost certainly not what you want
\begin{spacing}{1.0}
\fontsize{12}{12}\normalfont% is this a requirement? Because it will give you ugly output which is hard to read
abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract
\end{spacing}
\afterabstract
\prefacesection{Acknowledgements}
I would like to thank......
\afterpreface
\chapter{Introduction}
\section{Background}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background2}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background3}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\end{document}
答案2
您可以透過使用標識偶數頁碼和奇數頁碼以及要使用的頁眉一側的選項來標識每一側來定義每一側。這種格式來自我正在寫的一本書,它將標題推到打開頁面的「外部」。
\fancyhead{} % clear all header fields
\fancyhead[RO]{The Book Title} % [RO] here means Right/Odd numbered page
\fancyhead[LE]{\chaptername \ \thechapter} % {LE] here means Left/Even numbered page
在您的情況下,包括 \thepage 以便在您想要的任何位置插入頁碼。
\fancyhead{} % clear all header fields
\fancyhead[RO]{\chaptername \ \thechapter \ \thepage} % [RO] here means Right/Odd numbered page
\fancyhead[LE]{\chaptername \ \thechapter \ \thepage} % {LE] here means Left/Even numbered page