使用fancyhdr
包,我对每个带星号的部分执行的操作如下,将它们打印在标题上,例如:
\chapter*{{Foreword}} \markboth{{Foreword}}{Foreword}
以下是我在序言的相关章节中的内容:
\fancyhead[RE,RO]{\normalfont\scriptsize\thepage}
\fancyhead[LE]{\sffamily\small {My Book}
\fancyhead[LO]{\sffamily\small\\leftmark}
\fancyfoot{}
我如何才能实现自动化,以便不必为每个带星号的部分手动执行此操作?
凭借我(非常)有限的知识,我尝试过,
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
来自fancyhr
包装手册,但它不起作用。
MWE:(从 LyX 导出):
\documentclass[english]{book}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Minion Pro}
\setsansfont[Mapping=tex-text]{ITC Goudy Sans Std Book}
\usepackage[paperwidth=32pc,paperheight=48pc]{geometry}
\geometry{verbose,tmargin=9pc,bmargin=6pc,lmargin=5pc,rmargin=5pc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{array}
\makeatletter
\usepackage{enumitem}
\usepackage{yfonts,color}
\usepackage{xcolor}
\usepackage{colortbl}
\arrayrulecolor{lightgray}
\usepackage{titlesec}
\makeatletter
\@addtoreset{footnote}{section}
\makeatother
\renewcommand{\thechapter}{\Roman{chapter}}
\titleformat{\chapter}[display]
{\normalfont\scshape\normalsize\filcenter}
{\normalsize\MakeUppercase{\thechapter} }
{0pt}
{\vspace{1pt}%
\normalsize}
\titlespacing{\chapter}{0pt}{20pt}{80pt}
\titleformat{\section}
{\itshape\normalsize\filright}
{\MakeUppercase{\thesection.}}{.5em}{}
\titlespacing*{\section}{0pt}{60pt}{60pt}
\fancyhead[RE,RO]{\normalfont\scriptsize\thepage}
\fancyhead[LE]{\sffamily\small {My Book}
\fancyhead[LO]{\sffamily\small\\leftmark}
\fancyfoot{}
\makeatletter
\renewcommand*{\cleardoublepage}{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}%
\thispagestyle{empty}%
\newpage%
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
答案1
您可以添加到的版本\markboth
。我重新组织了对包和设置的调用。删除末尾仅用于在示例中生成模拟文本的。numberless
\chapter
kantlipsum
请注意避免手动emptypage
重新定义。\cleardoublepage
\addcontentsline
如果您需要目录,这并不会免除您的发行。
\documentclass[english]{book}
\usepackage[paperwidth=32pc,paperheight=48pc]{geometry}
\geometry{verbose,tmargin=9pc,bmargin=6pc,lmargin=5pc,rmargin=5pc}
\usepackage{fontspec}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{enumitem}
\usepackage{yfonts}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{titlesec}
\usepackage{chngcntr}
\usepackage{emptypage} % avoids redefining \cleardoublepage
\counterwithin*{footnote}{section}
\renewcommand{\thechapter}{\Roman{chapter}}
\titleformat{\chapter}[display]
{\normalfont\scshape\normalsize\filcenter}
{\normalsize\thechapter\ }
{0pt}
{\vspace{1pt}\normalsize}
\titleformat{name=\chapter,numberless}[display]
{\normalfont\scshape\normalsize\filcenter}
{}
{0pt}
{\vspace{1pt}\normalsize\addchaptertitle}
\titlespacing{\chapter}{0pt}{20pt}{80pt}
\newcommand{\addchaptertitle}[1]{%
#1\markboth{#1}{#1}%
}
\titleformat{\section}
{\itshape\normalsize\filright}
{\thesection.}
{.5em}
{}
\titlespacing*{\section}{0pt}{60pt}{60pt}
\pagestyle{fancy}
\fancyhead[RE,RO]{\normalfont\scriptsize\thepage}
\fancyhead[LE]{\sffamily\small My Book}
\fancyhead[LO]{\sffamily\small\leftmark}
\fancyfoot{}
\arrayrulecolor{lightgray}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setmainfont{Minion Pro}
\setsansfont{ITC Goudy Sans Std Book}
\usepackage{kantlipsum} % mock text
\begin{document}
\mainmatter
\chapter*{Introduction}
\kant[1-4]
\chapter{First}
\kant[5-8]
\end{document}
我将仅显示包含所需标题的第 3 页。