这是我的双面文档的页眉。 如您所见,当数字增加时,将页码与章节名称分开的垂直线会向内移动一点。我希望将此线的位置固定并与页面的文本框对齐。这是我的代码:
\documentclass [11pt, a4paper, twoside, openright]{book}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{xcolor}
\geometry{
inner=2.4cm, % Inner margin
outer=4cm, % Outer margin
top=3.5cm, % Top margin
bottom=3cm, % Bottom margin
heightrounded,
bindingoffset=4mm,
showframe,
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[LE]{\thepage\hspace{7pt}\textcolor{gray}{|}\hspace{5pt}\nouppercase{\textcolor{gray}{\leftmark}}}
\fancyhead[RO]{\nouppercase{\textcolor{gray}{\rightmark}}\hspace{5pt}\textcolor{gray}{|}\hspace{7pt}\thepage}
答案1
如果要在页边距中偏移页码,则需要使用\fancyhfoffset
。将页码括在与偏移量一样宽的框中(并且足够大以容纳最宽的罗马页码)。
\documentclass [11pt, a4paper, twoside, openright]{book}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{kantlipsum}
\geometry{
inner=2.4cm, % Inner margin
outer=4cm, % Outer margin
top=3.5cm, % Top margin
bottom=3cm, % Bottom margin
headheight=13.6pt,
heightrounded,
bindingoffset=4mm,
showframe,
}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}
\fancyhfoffset[LE]{20pt}
\fancyhfoffset[RO]{20pt}
\fancyhead[LE]{%
\makebox[20pt][l]{\thepage}%
{\color{gray}\makebox[0pt]{\textbar}\hspace{5pt}\nouppercase{\leftmark}}%
}
\fancyhead[RO]{%
{\color{gray}\nouppercase{\rightmark}\hspace{5pt}\makebox[0pt]{\textbar}}%
\makebox[20pt][r]{\thepage}%
}
\begin{document}
\frontmatter
\chapter{Introduction}
\section{Abstract}
\kant[1-40]
\end{document}
我还将栏设置在零宽度框中。