
我想知道怎麼可能中心章節和章節用這個(MWE)代碼標記(我不知道他們是否這麼稱呼它)
\documentclass[10pt,twoside]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[RE]{\leftmark}
\fancyhead[LO]{\rightmark}
\fancyhead[LE,RO]{\thepage}
\renewcommand\headrulewidth{0pt}
\renewcommand\chaptermark[1]{\markboth{\scshape#1}{}}
\renewcommand\sectionmark[1]{\markright{\scshape #1}}
\begin{document}
\chapter{chapter} % Even page header
\lipsum[1]
\section{section} % odd page header
\lipsum[1-5]
\end{document}
答案1
這是一個代碼。您忘記將頁面樣式宣告為「花式」:
\documentclass[10pt,twoside]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[CE]{\leftmark}
\fancyhead[CO]{\rightmark}
\fancyhead[LE,RO]{\thepage}
\renewcommand\headrulewidth{0pt}
\renewcommand\chaptermark[1]{\markboth{\scshape#1}{}}
\renewcommand\sectionmark[1]{\markright{\scshape #1}}
\pagestyle{fancy}
\begin{document}
\chapter{A First Chapter} % Even page header
\lipsum
\section{A section} % odd page header
\lipsum[1-10]
\end{document}
編輯:如果您只想在標題中包含標題,則更容易使用titleps
:
\documentclass[10pt,twoside]{book}
\usepackage{lipsum}
\usepackage{titleps}
\newpagestyle{mine}[\scshape]{%
\sethead[\thepage][\chaptertitle][]{}{\sectiontitle}{\thepage}
}
\pagestyle{mine}
\begin{document}
\chapter{A First Chapter} % Even page header
\lipsum
\section{A section} % odd page header
\lipsum[1-10]
\end{document}