我有以下 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}
\newpagestyle{mystyle}{
\sethead[][][\chaptertitle]{\thesection~\sectiontitle}{}{\thepage}}
\begin{document}
\pagestyle{mystyle}
\chapter{A chapter}
\lipsum[1-40]
\end{document}
這成功地從章節標題中刪除了“章節”一詞。不過我也想包括章節數。像'1。介紹'。如何使用 titlesec 執行此操作?
答案1
display
如果您希望章節標籤與章節標題位於同一行,則不應使用該樣式。使用預設hang
樣式,或者block
如果您想將其居中。 Notetwoside
不是必要的:它是book
類別中的預設值。fancyhdr
如果您想titlesec
與pagestyles
加載 的選項一起使用,也不要加載titleps
,並且它可能與 發生衝突fancyhdr
。
這是一個代碼:
\documentclass{book}
\usepackage[a4paper, width=150mm, vmargin=25mm, headheight=28pt, bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\titleformat{\chapter}%
{\normalfont\bfseries\Huge}{\thechapter.}{10pt}{}
\newpagestyle{mystyle}{
\sethead[][\thechapter.\enspace\chaptertitle][]{}{\thesection~\sectiontitle}{}
\setfoot{}{\thepage}{}}
\begin{document}
\pagestyle{mystyle}
\chapter{A Chapter}
\lipsum[1-5]
\section{A First Section}
\lipsum[6-20]
\end{document}