我遇到的问题是,在我的标题中提到了“章节”,但我只希望显示章节编号和名称。
\documentclass[a4paper, openany]{book}
\usepackage{fancyhdr}
\usepackage{titlesec}
\titleformat{\chapter}{\normalfont\huge}{\Huge \bf \thechapter}{20pt}{\Huge \bf} %This is here, so that at each chapter start, I only get "chapter number + chapter name"
\fancyhead[RO]{\rightmark}
\fancyhead[LE]{\leftmark}
\fancyfoot[RO,LE]{\thepage}
\begin{document}
\chapter{dsfjdj}
\newpage
\end{document}
右侧标记按我想要的方式工作,但左侧标记不工作,因为它还明确列出了单词“章节”。我该如何避免这种情况?
答案1
既然您使用titlesec
,我建议您使用titleps
,在我看来,它比 更易于使用fancyhdr
。它允许使用简单的语法定义新的页面样式,而无需使用标记:
\documentclass[a4paper, openany]{book}
\usepackage[pagestyles]{titlesec}
\usepackage{titlecaps}
\titleformat{\chapter}{\normalfont\huge \bfseries}{\Huge \thechapter}{20pt}{\Huge} %This is here, so that at each chapter start, I only get "chapter number + chapter name"
\newpagestyle{myps}{%
\sethead[\small\scshape\thechapter. ~\titlecap{\chaptertitle}][][]{}{}{\small\thesection.~\itshape\sectiontitle}
\setfoot{}{\thepage}{}
}%
\usepackage{lipsum}
\pagestyle{myps}
\begin{document}
\chapter{A first chapter}
\lipsum[1-3]
\section{Some section}
\lipsum
\end{document}
答案2
我使用了@John Kormylo 发布的链接并做了一些修改。这样,我就得到了想要的结果。
\documentclass[a4paper, openany]{book}
\usepackage{fancyhdr}
\usepackage{titlesec}
\titleformat{\chapter}{\normalfont\huge}{\Huge \bf \thechapter}{20pt}{\Huge \bf} %This is here, so that at each chapter start, I only get "chapter number + chapter name"
\fancyhead[RO]{\rightmark}
\fancyhead[LE]{\leftmark}
\fancyfoot[RO,LE]{\thepage}
\makeatletter
\renewcommand*{\chaptermark}[1]{%
\markboth{
\uppercase{\thechapter \, #1}
}{}%
}%
\makeatother
\makeatletter
\renewcommand*{\sectionmark}[1]{%
\markright{%
\uppercase{\thesection \, #1}
}{}%
}%
\makeatother
\begin{document}
\chapter{dsfjdj}
\newpage
\end{document}