\fancypagestyle{fancybook}{%
\fancyhf{}%
\renewcommand*{\sectionmark}[1]{ \markright{\thesection\ ##1} }%
\renewcommand*{\chaptermark}[1]{ \markboth{\chaptername\ \thechapter: ##1}{} }%
\fancyhfoffset[LE]{6mm}% slightly less than 0.25in
\fancyhfoffset[RO]{6mm}%
%
\fancyhead[LE]{\thepage\hskip3mm\vrule\hskip3mm\leftmark}%
\fancyhead[RO]{\rightmark\hskip3mm\vrule\hskip3mm\thepage}%
}
\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{\chaptername\ \thechapter.\ #1}}{}}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\frontmatter
\pagenumbering{roman}
\title {book title here}
\author{name}
\date{\today}
\maketitle
\tableofcontents
\cleardoublepage
%\thispagestyle{plain}
\renewcommand\bibname{References}
\bibliographystyle{IEEEtran}
\normalsize
\begin{singlespace}
\chapter{Preface}
\addcontentsline{toc}{chapter}{Preface}
\input{content/0_preface}
\chapter{Acknowledgments}
\addcontentsline{toc}{chapter}{Acknowledgments}
\input{content/0_acknow}
\end{singlespace}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mainmatter
\pagenumbering{arabic}
答案1
也许你想要这样的东西?
\documentclass{book}
\usepackage{fancyhdr}
\usepackage{emptypage}% no header on otherwise empty pages
\usepackage{lipsum}
\fancypagestyle{fancybook}{%
\fancyhf{}%
\fancyhfoffset[LE]{6mm}% slightly less than 0.25in
\fancyhfoffset[RO]{6mm}%
\fancyhead[LE]{%
\thepage\hspace{3mm}\vrule\hspace{3mm}%
\ifnum\value{chapter}>0
\MakeUppercase{\chaptername\ \thechapter.\ }%
\fi
\leftmark
}%
\fancyhead[RO]{%
\rightmark
\hspace{3mm}\vrule\hspace{3mm}\thepage
}%
}
\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\pagestyle{fancybook}
\begin{document}
\frontmatter
\title{book title here}
\author{name}
\date{\today}
\maketitle
\tableofcontents
\chapter{Preface}
This is the text of the preface
\lipsum[1-10]
\chapter{Acknowledgments}
This is the text of the acknowledgments
\lipsum[1-10]
\mainmatter
\chapter{The first chapter}
\section{A section}
\lipsum[1-10]
\end{document}
请注意\frontmatter
问题\pagenumbering{roman}
和\mainmatter
问题\pagenumbering{arabic}
,因此无需再次声明。
前言中的章节会自动添加到目录中。
我不确定我是否希望小垂直规则根据页码的长度移动。