fancyhdr 颜色和线宽?

fancyhdr 颜色和线宽?

我正在使用 fancyhdr 包,我想在标题下添加一条更粗的线条,并且希望它带有颜色,但我的问题是这两个命令:

\renewcommand{\headrule}{\vbox to 0pt{\hbox
to\headwidth{\textcolor{headercolor}{\hrulefill}}\vss}} 
\renewcommand{\headrulewidth}{2pt}

不能一起工作吗?那么我怎样才能得到更粗且有颜色的线条呢?

完整代码如下:

\documentclass{book}
\usepackage{geometry}

\geometry{left=4cm,right=3cm, top=2cm, bottom=2cm} 

\usepackage{titlesec}
\titlespacing*{\chapter}{0pt}{-30pt}{20pt}
\titleformat{\chapter}[display]{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\usepackage[ngerman]{babel}
\usepackage{mathptmx}
\usepackage{helvet}
\usepackage{wallpaper}
\usepackage{color}
\usepackage[final]{pdfpages} 

\usepackage{xcolor,bookmark}
\usepackage{scrextend}
\usepackage{titlepic}
\usepackage{shorttoc}
\usepackage{courier}
%\usepackage{titlesec}
%\usepackage[titles]{tocloft}

\usepackage{type1cm}         
\usepackage{zref-abspage}



    \usepackage{makeidx}        

    \usepackage{graphicx}                                         
  \usepackage{multicol}       
   \usepackage{thmbox}
    \usepackage{shadethm}
    \usepackage{amsthm}
    \usepackage{amsmath}
    \usepackage{marginnote}
    %\usetocstyle{KOMAlike}
    \usepackage{wrapfig}
    \usepackage{paralist}
    \usepackage{amssymb}
    \usepackage[framemethod=tikz]{mdframed}
    \usepackage{ulem}
    \usepackage{fancyheadings}
    %\usepackage{sectsty}

    \definecolor{headercolor}{rgb}{0.6941,0.6745,0.4863}


    \begin{document}

\mainmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\include{part1} 
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{ \textcolor{headercolor}\leftmark \text{ }\textcolor{headercolor}{\thesection}}
\fancyhead[R]{\textcolor{headercolor}{\thepage}}
%\renewcommand{\headrule}{\vbox to 0pt{\hbox
%to\headwidth{\textcolor{headercolor}{\hrulefill}}\vss}} 
\renewcommand{\headrulewidth}{2pt}
 test test\\ test test    

\end{document}

答案1

您需要\headrulewidth在重新定义中纳入\headrule,因为\hrulefill使用不同的宽度规则:

\renewcommand{\headrulewidth}{2pt}% 2pt header rule
\renewcommand{\headrule}{\hbox to\headwidth{%
  \color{headercolor}\leaders\hrule height \headrulewidth\hfill}}

下面是一个非正式的 MWE,它使用上述技术构建页面样式myheader

在此处输入图片描述

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\fancypagestyle{myheader}{%
  \fancyhf{}% Clear all headers/footers
  \fancyhead[C]{My header}% Header Centred
  \fancyfoot[C]{-\thepage-}% Footer Centred
  \renewcommand{\headrulewidth}{2pt}% 2pt header rule
  \renewcommand{\headrule}{\hbox to\headwidth{%
    \color{red}\leaders\hrule height \headrulewidth\hfill}}
  \renewcommand{\footrulewidth}{0pt}% No footer rule
}
\setlength{\headheight}{21pt}%
\begin{document}
\pagestyle{myheader}
\lipsum[1-20]
\end{document}

相关内容