我有以下 MWE:
\documentclass[twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}
\newpagestyle{mystyle}{
\sethead[][][\thechapter.\quad\chaptertitle]{\sectiontitle}{}{\thepage}
\setfoot[][\thepage][]{\thesection~\sectiontitle}{}{\thepage}}
\begin{document}
\pagestyle{mystyle}
\chapter{Introduction}
\lipsum[1-40]
\end{document}
它僅在偶數頁上產生自訂頁眉。在奇數頁上,它顯示頁碼。如何讓它在奇數頁和偶數頁的中央位置顯示自訂標題(1.簡介)?
答案1
要引入\sectiontitle
標題,您應該提供\section
檢查以下內容:
\documentclass[twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}
\newpagestyle{mystyle}{
\sethead[][][\thechapter.\quad\chaptertitle]{}{}{\thesection~\sectiontitle}
\setfoot[][\thepage][]{}{\thepage}{}}
\begin{document}
\pagestyle{mystyle}
\chapter{Introduction}
\lipsum[1-5]
\section{H1 for test}
\lipsum[1-15]
\end{document}
希望能幫助你!