问题描述
我希望在页眉/页脚文本和页眉/页脚规则之间设置固定间距。我尝试过设置页眉规则、页脚规则和文本之间的相同距离而这并不是我想要的。对于标题,长标题文本的最后一行和标题规则之间的间距与单行标题文本和相应标题规则之间的间距不同。换句话说,我们能否修复此间距,使其对于单行(短标题文本)和多行(长标题文本)标题文本都保持不变?鉴于已经找到了标题文本和标题规则的解决方案,我想将标题规则和标题文本之间使用的固定间距也应用于脚规则和页脚文本。以下是我的 MWE:
% !TeX TS-program = pdflatex
\documentclass[12pt,openany,twoside]{book}
\raggedbottom
\usepackage[
left=2.5cm,
right=2.5cm,
top=3cm,
bottom=3cm,
headheight = 3.5\baselineskip,
headsep = 5mm,
a4paper
]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}
\usepackage{background}
\backgroundsetup{contents={}}
\usepackage{fancyhdr}
\usepackage{hhline}
\usepackage{helvet}
\usepackage{tabularx}%
\newcommand*\myheaderfooterfont{\sffamily\bfseries\selectfont}
\newlength{\leftspace}% for sections <<<<<<<<<
\setlength{\leftspace}{20ex}%set
\newlength{\Lheader}
\renewcommand{\chaptermark}[1]{\markboth{\uppercase{#1}}{}}%
\renewcommand{\sectionmark}[1]{\markright{\uppercase{#1}}}%
\fancypagestyle{fancy}{%
\fancyhf{}
\fancyhead[OL]{\myheaderfooterfont%
\ifnum\value{chapter}>0%
\begin{tabularx}{\textwidth}{@{}lX}\uppercase{Chapter~\thechapter}&\raggedright\leftmark\end{tabularx}% changed <<<<<<<<<<
\else\raggedright\leftmark\relax\fi}
\fancyhead[ER]{\myheaderfooterfont%
\settowidth{\Lheader}{\thesection\hspace*{12pt}\rightmark}
\ifnum\value{chapter}>0%
\ifdim\Lheader>\linewidth%
\begin{tabularx}{\dimexpr\textwidth-\leftspace}{@{}lX} \thesection &\raggedright\rightmark\end{tabularx}%
\else\begin{tabular}{@{}ll@{}} \thesection &\raggedright\rightmark\end{tabular}%
\fi\else\hfill\raggedright\rightmark\relax\fi
}% changed <<<<<
\fancyfoot{}
\fancyfoot[RE,RO]{\myheaderfooterfont\thepage}%last added<<<<<<<
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<last added
\renewcommand\headrule
{{ \color{blue}\rule{0.33\headwidth}{2.5pt}% <---
\color{red}\rule{0.34\headwidth}{2.5pt}% <---
\color{orange}\rule{0.33\headwidth}{2.5pt}% <---
}}
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<last added
}
\fancypagestyle{plain}{%
\fancyhf{}%
\renewcommand\headrule
{{ \color{blue}\rule{1\headwidth}{0pt}%
}}
\fancyfoot{}
\fancyfoot[RE,RO]{\myheaderfooterfont\thepage} %last added<<<<<<
}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{1pt}
\usepackage{showframe}
\usepackage[none]{hyphenat}
\raggedright % important with none hyphenat + none !!!!!!!!!!!!!!!!!
\begin{document}
%<<<<<<<<<<<<<<<<<<<<<<<<<last added
\begin{titlepage}
\setlength{\parindent}{0in}
\topskip 360pt
\vspace*{\fill}
\centering
\scshape
\begin{flushleft}
{ \textbf{HHHHHHHHHHHHHHHHHHHHHHHHGFFFFFFFFFFF}
}
\end{flushleft}
\vspace*{3\baselineskip}
\textbf{AUTHOR}
\vspace{0.5\baselineskip}
{\scshape\Large\selectfont LKJJHHHG}
\vspace{1.5\baselineskip}
\textbf{PFEYTYU}
\vspace{1\baselineskip}
{\scshape\Large\selectfont JKIU}
\vspace{2\baselineskip}
\textbf{YUUUUH}
\vspace{0.5\baselineskip}
{\scshape\Large\selectfont 12345}
\vspace{0.5\baselineskip}
\vfill
\vspace{4\baselineskip}
\scshape
Revised: \today
\end{titlepage}
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<last added
\frontmatter
\chapter*{ABC}
\markboth{ABC1}{ABC2}
eeeheeyeyeyeyeyeeyeye
\section*{DEG}
dddheheheheheheheehehehe
\pagebreak
\section*{KJ}
ddhheheheheheehehehheheheheheh
\pagebreak
\section*{KDH}
dhddhhehehehehehehehehehehe
\mainmatter
\chapter{ABCD ffhfgrhr ejejejeje fhfhfhf ehehehehe dhddhdhellgl rkttkgkhihi eeeejejwnwn hhlhlnnmgjgj rjrrjoaoaoao }
eehehdhdhdhdddddd ddddddddddddddddddddd
\newpage
\section{Special keyboard characters gghthr rhrrhd fheheh fhehuw fhewiwi feiwiwd fiiwiwid fiiwiwi}
\LaTeX{} hasmany symbols at its disposal. The majority of them are within the mathematical domain as shown in \eqref{eq:1} and \eqref{eq:2}. The ten special keyboard characters are: \verb|#|, \verb|$|, \verb|%|, \verb|&|, \verb|~|, \verb|_|, \verb|^|, \verb|\| and \verb|{}|. If you simply want the character to be printed just as any other letter, include a \verb|\ | in front of the character. For example, \verb|\$| will produce \verb|$| in your output.
The exception to the rule is the \verb|\ | itself because \verb|\\ | has its own special meaning. A \verb|\ | is produced by typing \verb|$\backslash$| in your file.
\newpage
\section{Special keyboard characters}
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\newpage
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\chapter{One short line}
\LaTeX{} has many symbols at its disposal. The majority of them are within the mathematical domain as shown in \eqref{eq:1} and \eqref{eq:2}. The ten special keyboard characters are: \verb|#|, \verb|$|, \verb|%|, \verb|&|, \verb|~|, \verb|_|, \verb|^|, \verb|\| and \verb|{}|. If you simply want the character to be printed just as any other letter, include a \verb|\ | in front of the character. For example, \verb|\$| will produce \verb|$| in your output.
The exception to the rule is the \verb|\ | itself because \verb|\\ | has its own special meaning. A \verb|\ | is produced by typing \verb|$\backslash$| in your file.
\section{Special keyboard characters}
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\newpage
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\newpage
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\end{document}
答案1
编辑:代码已适应最新的 MWE。已添加完整代码。见下文。
我会解释发生了什么。您\headrule
使用\rule
命令。这是一个“水平”命令,这意味着它成为包含标题文本的段落的一部分。它会转到此段落的新行,因为它不适合标题文本,当然,这正是您想要的。但是 TeX 随后会确保标题文本的基线与此规则的基线之间的距离至少为\baselineskip
。这就是为什么单行标题中的标题和规则之间的距离如此之大的原因。
对于带有 的多行页眉\tabular(x)
,页眉的基线是多行页眉的第一行。因此页眉基线与规则的距离已经大于,\baselineskip
并且没有添加额外的空间。
标准定义\headrule
使用fancyhdr
命令\hrule
,这是一个垂直模式命令。因此它不是段落的一部分,只是固定在标题文本的底部。(基线和规则之间的距离由 保证\strut
。)
因此,一个解决方案是定义你\headrule
的\hrule
:
\renewcommand\headrule{\color{blue}\hrule height 2.5pt}
另一种可能性是将命令包含\nointerlineskip
在你的 之前\rule
。这告诉 Tex 不要添加额外的\baselineskip
。
\renewcommand\headrule{\nointerlineskip\color{blue}\rule{\headwidth}{2.5pt}}
现在来看看页脚:
和页脚文本之间的距离\footrule
由 定义footruleskip
。但这不是规则和文本顶部之间的距离,因为\strut
页脚中还有一个。这样做是为了让脚规则和页脚基线之间的距离保持一致。否则,这个距离将取决于页脚中是否有大写字母或只有小写字母。我认为这不美观。所以我建议保留它。无论如何,删除 都很困难\strut
。在您的情况下,如果页脚中只有数字(并且在此字体中它们都具有相同的高度),则无关紧要。
您可以测量数字的高度,但我认为目测就足够了。我建议:
\renewcommand{\footruleskip}{3pt}
完整代码(我的更改由 表示%%%%%%%% PVO %%%%%%%%%%
)
\documentclass[12pt,openany,twoside]{book}
\raggedbottom
\usepackage[
left=2.5cm,
right=2.5cm,
top=3cm,
bottom=3cm,
headheight = 3.5\baselineskip,
headsep = 5mm,
a4paper
]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}
\usepackage{background}
\backgroundsetup{contents={}}
\usepackage{fancyhdr}
\usepackage{hhline}
\usepackage{helvet}
\usepackage{tabularx}%
\newcommand*\myheaderfooterfont{\sffamily\bfseries\selectfont}
\newlength{\leftspace}% for sections <<<<<<<<<
\setlength{\leftspace}{20ex}%set
\newlength{\Lheader}
\renewcommand{\chaptermark}[1]{\markboth{\uppercase{#1}}{}}%
\renewcommand{\sectionmark}[1]{\markright{\uppercase{#1}}}%
\fancypagestyle{fancy}{%
\fancyhf{}
\fancyhead[OL]{\myheaderfooterfont%
\ifnum\value{chapter}>0%
\begin{tabularx}{\textwidth}{@{}lX}\uppercase{Chapter~\thechapter}&\raggedright\leftmark\end{tabularx}% changed <<<<<<<<<<
\else\raggedright\leftmark\relax\fi}
\fancyhead[ER]{\myheaderfooterfont%
\settowidth{\Lheader}{\thesection\hspace*{12pt}\rightmark}
\ifnum\value{chapter}>0%
\ifdim\Lheader>\linewidth%
\begin{tabularx}{\dimexpr\textwidth-\leftspace}{@{}lX} \thesection &\raggedright\rightmark\end{tabularx}%
\else\begin{tabular}{@{}ll@{}} \thesection &\raggedright\rightmark\end{tabular}%
\fi\else\hfill\raggedright\rightmark\relax\fi
}% changed <<<<<
\fancyfoot{}
\fancyfoot[RE,RO]{\myheaderfooterfont\thepage}%last added<<<<<<<
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<last added
\renewcommand\headrule
{{ \nointerlineskip %%%%%%%% PVO %%%%%%%%%%
\color{blue}\rule{0.33\headwidth}{2.5pt}% <---
\color{red}\rule{0.34\headwidth}{2.5pt}% <---
\color{orange}\rule{0.33\headwidth}{2.5pt}% <---
}}
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<last added
}
\fancypagestyle{plain}{%
\fancyhf{}%
\renewcommand\headrule
{{ \color{blue}\rule{1\headwidth}{0pt}%
}}
\fancyfoot{}
\fancyfoot[RE,RO]{\myheaderfooterfont\thepage} %last added<<<<<<
}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{1pt}
\renewcommand{\footruleskip}{3pt} %%%%%%%% PVO %%%%%%%%%%
\usepackage{showframe}
\usepackage[none]{hyphenat}
\raggedright % important with none hyphenat + none !!!!!!!!!!!!!!!!!
\begin{document}
%<<<<<<<<<<<<<<<<<<<<<<<<<last added
\begin{titlepage}
\setlength{\parindent}{0in}
\topskip 360pt
\vspace*{\fill}
\centering
\scshape
\begin{flushleft}
{ \textbf{HHHHHHHHHHHHHHHHHHHHHHHHGFFFFFFFFFFF}
}
\end{flushleft}
\vspace*{3\baselineskip}
\textbf{AUTHOR}
\vspace{0.5\baselineskip}
{\scshape\Large\selectfont LKJJHHHG}
\vspace{1.5\baselineskip}
\textbf{PFEYTYU}
\vspace{1\baselineskip}
{\scshape\Large\selectfont JKIU}
\vspace{2\baselineskip}
\textbf{YUUUUH}
\vspace{0.5\baselineskip}
{\scshape\Large\selectfont 12345}
\vspace{0.5\baselineskip}
\vfill
\vspace{4\baselineskip}
\scshape
Revised: \today
\end{titlepage}
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<last added
\frontmatter
\chapter*{ABC}
\markboth{ABC1}{ABC2}
eeeheeyeyeyeyeyeeyeye
\section*{DEG}
dddheheheheheheheehehehe
\pagebreak
\section*{KJ}
ddhheheheheheehehehheheheheheh
\pagebreak
\section*{KDH}
dhddhhehehehehehehehehehehe
\mainmatter
\chapter{ABCD ffhfgrhr ejejejeje fhfhfhf ehehehehe dhddhdhellgl rkttkgkhihi eeeejejwnwn hhlhlnnmgjgj rjrrjoaoaoao }
eehehdhdhdhdddddd ddddddddddddddddddddd
\newpage
\section{Special keyboard characters gghthr rhrrhd fheheh fhehuw fhewiwi feiwiwd fiiwiwid fiiwiwi}
\LaTeX{} hasmany symbols at its disposal. The majority of them are within the mathematical domain as shown in \eqref{eq:1} and \eqref{eq:2}. The ten special keyboard characters are: \verb|#|, \verb|$|, \verb|%|, \verb|&|, \verb|~|, \verb|_|, \verb|^|, \verb|\| and \verb|{}|. If you simply want the character to be printed just as any other letter, include a \verb|\ | in front of the character. For example, \verb|\$| will produce \verb|$| in your output.
The exception to the rule is the \verb|\ | itself because \verb|\\ | has its own special meaning. A \verb|\ | is produced by typing \verb|$\backslash$| in your file.
\newpage
\section{Special keyboard characters}
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\newpage
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\chapter{One short line}
\LaTeX{} has many symbols at its disposal. The majority of them are within the mathematical domain as shown in \eqref{eq:1} and \eqref{eq:2}. The ten special keyboard characters are: \verb|#|, \verb|$|, \verb|%|, \verb|&|, \verb|~|, \verb|_|, \verb|^|, \verb|\| and \verb|{}|. If you simply want the character to be printed just as any other letter, include a \verb|\ | in front of the character. For example, \verb|\$| will produce \verb|$| in your output.
The exception to the rule is the \verb|\ | itself because \verb|\\ | has its own special meaning. A \verb|\ | is produced by typing \verb|$\backslash$| in your file.
\section{Special keyboard characters}
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\newpage
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\newpage
Special keyboard characters dhgdgdg dgdgdgdg ggdgdgd egegegege dgddgdgd eggegegeg dgdgdgdgd egegegeg dggeieieirr tktii43iwje rfrhrhrhr gtktotyiyighgjgj fkf
\end{document}