我正在用
\documentclass[12pt, oneside]{book}
使用文档类“book”,我会自动获取我不想要的“第 # 章”标题,并使用以下命令使用 titlesec 将其删除
\usepackage[pagestyles]{titlesec}
\titleformat{\chapter}[display]{\normalfont\bfseries}{}{0pt}{\Huge}
所以现在我想将页码放在右下角,并希望标题以它所在的章节或部分命名。我尝试使用以下命令执行此操作
\documentclass[12pt, oneside]{book}
\pagestyle{plain}
Latex 代码
% The \usepackage{} command will import predefined fonts, symbols, environments, etc. For example, the ams packages below come from the American Mathematical Society and include all kinds of useful math symbols like integrals
\usepackage{amscd}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{verbatim}
\usepackage[utf8]{inputenc}
\usepackage{geometry} % See geometry.pdf to learn the layout options. There are lots.
\geometry{a4paper} % ... or a4paper or a5paper or ...
%\geometry{landscape} % Activate for for rotated page geometry
\usepackage[pdftex]{graphicx} % Use pdf, png, jpg, or eps with pdflatex; use eps in DVI mode
\usepackage{setspace}
\usepackage{physics}
\usepackage{subcaption}
\usepackage[numbers]{natbib}
\usepackage{pdfpages}
\usepackage{bm}
\usepackage{wrapfig} % enables the use of \wrapfig, for figures with text wrapped around them
\usepackage{afterpage}
\newcommand\blankpage{%
\null
\thispagestyle{empty}%
\addtocounter{page}{-1}%
\newpage}
\usepackage{bibentry} % for list of publications
\usepackage{hyperref}
% \usepackage[english]{babel}
\graphicspath{{images/}{{\subfix{images/}}}}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes,calc,positioning}
\tdplotsetmaincoords{70}{120}
\usepackage{siunitx}
\usepackage{adjustbox}
\usepackage{xcolor} %% Text color
\usepackage{blindtext}
\usepackage{subfiles} % Best loaded last in the preamble
\usepackage{multicol,multirow} %% Figure in two columns
\usepackage{mathtools, nccmath}
\usepackage{lipsum} % gives access to \lipsum, which dumps some latin text into your document as filler if you want to check formatting
%\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent
%my additions
\usepackage{graphicx}
\usepackage{fancyhdr, graphicx}
\usepackage[pagestyles]{titlesec}
\titleformat{\chapter}[display]{\normalfont\bfseries}{}{0pt}{\Huge}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{\leftmark}
\fancyfoot[R]{\thepage}
\fancypagestyle{plain}{
\renewcommand\headrulewidth{0pt}
\fancyhf{}
\fancyfoot[R]{\thepage}
}
% Here we set the page dimensions to match the standard thesis format. These values should not be changed.
%%% SET LENTGH AND WIDTH %%%
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{8.5in}
\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\topmargin}{0pt}
\setlength{\marginparsep}{0pt}
\setlength{\marginparwidth}{1in}
%\begin{document} starts LaTeX looking for actual content. Everything above this point is purely formatting.
\begin{document}
\begin{titlepage}
\begin{center}
% \vspace* creates some vertical white space on the page to make the title page look more pleasing. \vspace would do much the same thing, but would not insert the white space if we were at the top of a fresh page. As this is the start of the document we're obviously at the beginning of a page, so the asterisk is necessary to ensure we still put in two cm of white space.
\vspace{1cm}
\large{Master's thesis}
\vspace{0.5cm}
{\huge \textbf{Title}} % \huge sets the font size. Other options include things like \large, \Large, \small, \tiny, etc.
\noindent\rule{16cm}{0.5pt}
\vspace{1 cm}
% \vfill creates an arbitrary amount of vertical white space as necessary to fill the page
\vfill
% \vspace*{3cm}
\end{center}
\end{titlepage}
%_____________________________________________________________
% \frontmatter defines the pieces of the thesis which will use roman numerals for page numbering
\frontmatter
% \chapter{} and/or \chapter*{} will create a chapter in your thesis. Including the asterisk will cause the chapter to not appear in the table of contents.
\chapter{Preface}
\input{Chapters/Preface}
%\tableofcontents will create a table of contents. By default it will include entries for any \chapter, \section, and \subsection command that appears in your thesis unless you have called the tag with an asterisk
\tableofcontents
\listoftables
\listoffigures
%_____________________________________________________________
% The \mainmatter command defines the main body of the thesis and indicates where regular numbering starts
\mainmatter
\newpage
\chapter{Introduction}
\chead{Introduction}
\input{Chapters/Introduction}
%_____________________________________________________________
% the \appendix tag tells LaTeX where it should start labelling chapters with letters (denoting appendices) rather than numbers (denoting main chapters)
\appendix
% \bibliographystyle command to choose the format of your bibliography. More examples of bibliography styles can be found at https://www.overleaf.com/learn/latex/Bibtex_bibliography_styles
\bibliographystyle{naturemag}
% \bibliography is the command for the actual file containing your bibliographic data. This file can be produced manually or automatically using software such as BibTeX. Both options can work, however, learning to use BibTex is beneficial in the long run. An example of the format needed to generate your own bibliography file can be found as the bibliography.bib file here provided.
\bibliography{references}
\end{document}
答案1
不建议同时使用titleps
(如pagestyles
选项所暗示的那样)和fancyhdr
。但是,只要小心谨慎,这是可以的。但是,fancyhdr
不应在之前加载,\usepackage[pagestyles]{titlesec}
因为它们都定义了\headrule
。但是,fancyhdr
会检查这一点,因此可以在之后加载。
因此删除该行\usepackage{fancyhdr, graphicx}
并删除该选项pagestyles
:
\usepackage{titlesec}
那么它可能会起作用。
另一个问题:不要只定义页面尺寸:
% Here we set the page dimensions to match the standard thesis format. These values should not be changed.
%%% SET LENTGH AND WIDTH %%%
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{8.5in}
\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\topmargin}{0pt}
\setlength{\marginparsep}{0pt}
\setlength{\marginparwidth}{1in}
而是使用geometry
包来定义它们,并在加载之前完成fancyhdr
。否则,页面布局会出现不一致的情况,例如页眉太小。