我想创建一个像这样的精美页眉。我正在用 A5 纸写一本双面书。
答案1
scrlayer-scrpage
以下是使用的建议scrlayer-scrpage
。
\documentclass[a5paper]{book}
\setlength\headheight{13.1pt}
\usepackage{xcolor}
\colorlet{headbgcolor}{green!50!blue!70}
\usepackage[markcase=noupper]{scrlayer-scrpage}
\clearpairofpagestyles
\automark[chapter]{chapter}
\renewcommand\chaptermarkformat{\chaptername\ \thechapter:\enskip}
\lehead*{%
\makebox[0pt][r]{
\colorbox{headbgcolor}{\makebox[\textwidth][r]{\pagemark\enskip}}\hspace*{1em}}%
\headmark\hspace*{1em}\headrulefill%
}
\rohead*{%
\headrulefill\hspace*{1em}\headmark%
\makebox[0pt][l]{%
\hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip\pagemark}}}%
}
\addtokomafont{pagenumber}{\bfseries\color{white}}
\newcommand\headrulefill{\leaders\hrule width 0pt height 3pt depth -2.8pt \hfill}
\usepackage{blindtext}% dummy text
\begin{document}
\blinddocument
\end{document}
如果章节页不应该有页眉,请删除\lehead
和后面的星号\rohead
。
花式高清
下面是使用的示例花式高清
\documentclass[a5paper]{book}
\setlength\headheight{13.1pt}
\usepackage{xcolor}
\colorlet{headbgcolor}{green!50!blue!70}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand\chaptermark[1]{\markboth{\chaptername\ \thechapter:\enskip#1}{}}
\fancyhf{}
\fancyhead[LE]{%
\makebox[0pt][r]{
\colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries\textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
{\itshape\leftmark}\hspace*{1em}\headrulefill%
}
\fancyhead[RO]{%
\mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
\makebox[0pt][l]{%
\hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip\bfseries\textcolor{white}{\thepage}}}}%
}
\renewcommand\headrulewidth{0pt}
\def\headrulefill{\leaders\hrule width 0pt height 3pt depth -2.8pt \hfill}
\usepackage{blindtext}% dummy text
\begin{document}
\blinddocument
\end{document}
如果章节页面应该获得相同的标题,那么您也必须重新定义 fancypagestyle plain
。
\fancypagestyle{plain}{
\fancyhf{}
\fancyhead[LE]{%
\makebox[0pt][r]{
\colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries\textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
{\itshape\leftmark}\hspace*{1em}\headrulefill%
}
\fancyhead[RO]{%
\mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
\makebox[0pt][l]{%
\hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip\bfseries\textcolor{white}{\thepage}}}}%
}
}