使用提供的代码行这里成功更改了标题颜色,但在标题文本/颜色框(lheadtext、rheadtext)和标题之间产生了间隙:
有没有办法给标题栏上色而又不留空隙?
\documentclass[9pt]{extarticle}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{lhead text}
\chead{}
\rhead{\fcolorbox{black}{black}{
\footnotesize\bfseries{\makebox[4em]
{\color{white}rhead text}}}%
}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\headrule}{\hbox to\headwidth{\color{blue}\leaders\hrule height \headrulewidth\hfill}}
\begin{document}
text
\end{document}
答案1
您想避免标题文本和标题下方的线条之间的间隙吗?您可以修补\headrule
以更改线条的颜色:
\documentclass[9pt]{extarticle}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{lhead text}
\chead{}
\rhead{\fcolorbox{black}{black}{
\footnotesize\bfseries{\makebox[4em]
{\color{white}rhead text}}}%
}
\renewcommand{\headrulewidth}{1pt}
\usepackage{xpatch}
\xpretocmd\headrule{\color{blue}}{}{\PatchFailed}
\begin{document}
text
\end{document}
答案2
您可以使用 \setlength{headsep} 来调整标题和文本之间的距离。
\documentclass[9pt]{extarticle}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{lhead text}
\chead{}
\rhead{\fcolorbox{black}{black}{
\footnotesize\bfseries{\makebox[4em]
{\color{white}rhead text}}}%
}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\headrule}{\hbox to\headwidth{\color{blue}\leaders\hrule height \headrulewidth\hfill}}
%% set the gap between header and text
\setlength{\headsep}{0.1in}
\begin{document}
text
\end{document}
希望能帮助到你。
罗曼
答案3
\renewcommand{\headrule}{\color{red}\hrulefill}
完整代码。
\documentclass{article}
\usepackage{fancyhdr,xcolor}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\headrule}{\color{red}\hrulefill}
\lhead{Head}
\begin{document}
Text
\end{document}