我为每个章节设置了一个标题页,但我不明白为什么章节标题会出现在章节之前。
\documentclass[12pt, oneside]{book}
\usepackage{fancyhdr}
\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
\fancyhead[L]{}
\fancyhead[R]{\chaptername\ \thechapter\ --\ \leftmark}
\fancyfoot{}
\fancyfoot[R]{\thepage}
\renewcommand{\headrulewidth}{1pt}
\mainmatter
\titleclass{\chapter}{page}
\assignpagestyle{\chapter}{empty}
\titleformat{\chapter}
[display]
{\centering\Huge\bfseries}
{\chaptertitlename{}\ \thechapter}
{0pt}
{\huge}
[\clearpage]
\begin{document}
\pagestyle{fancy}
\input{chapters/chapter1}
\input{chapters/chapter2}
\input{chapters/chapter3}
\input{chapters/chapter4}
\input{chapters/chapter5}
\input{chapters/chapter6}
\end{document}
答案1
此代码使用了explicit
的参数titlesec
,以便\chapter
在使用章节标题时可以使用的格式设置来设置左边的标记。
该命令\renewcommand{\chaptermark}[1]{...
将左标记格式化为破折号。
\documentclass[12pt, oneside]{book}
\usepackage[explicit]{titlesec}% changed <<<<
\titleclass{\chapter}{page}
\assignpagestyle{\chapter}{empty}
\titleformat{\chapter}
[display]
{\centering\Huge\bfseries}
{\chaptertitlename{}\ \thechapter}
{0pt}
{\huge}
[#1\markboth{#1}{}\clearpage]% changed <<<<<<<<<<<<
\usepackage{fancyhdr}
\setlength{\headheight}{15pt}
\fancypagestyle{fancy}{%
\fancyhf{}
\fancyhead[R]{\nouppercase\leftmark}% changed <<<<<<<<<<
\fancyfoot[R]{\thepage}
\renewcommand{\headrulewidth}{1pt}
}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{% format the left mark <<<<
\markboth{\normalfont\sffamily\chaptername\ \thechapter\ -- #1}{}}
\usepackage{kantlipsum}% only dummy text
\begin{document}
\mainmatter% in here <<<<<<<<<<<<<<
\chapter{The First}
\kant[1-4]
\chapter{The Second}
\kant[1-4]
\chapter{Behavior, HPA Axis and Hormones}
\kant[1-4]
\chapter{GABA\textsubscript{A} Receptor Subunit Expression}
\section{Introduction}
\kant[1-4]
\end{document}