헤더 라인의 색상 변경

헤더 라인의 색상 변경

질문에 대한 답변fancyhdr - 바닥글 상단의 가로선 색상 변경예를 들어 이 예에서는 헤더 줄의 위치가 변경되기 때문에 완전히 만족스럽지 않습니다.

\documentclass{article}

\usepackage{xcolor}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\headrule}{\hbox to\headwidth{\color{red}\leaders\hrule height \headrulewidth\hfill}}
\fancyhead[LE,RO]{Hello}
\pagestyle{fancy}

\begin{document}
    hello
\end{document}

선의 위치는 바꾸지 않고 선의 색만 바꾸는 것이 가능한가요?

답변1

아래에서는 원본을 \headrule에 저장한 \oldheadrule다음 \color{<colour>}새로 정의 \headrule\oldheadrule. 접근 방식은 다음과 유사합니다.etoolbox\pretocmd.

여기에 이미지 설명을 입력하세요

\documentclass{article}

\usepackage{fancyhdr,xcolor}

\let\oldheadrule\headrule% Copy \headrule into \oldheadrule
\renewcommand{\headrule}{\color{red}\oldheadrule}% Add colour to \headrule
\renewcommand{\headrulewidth}{0.5pt}
\fancyhead{Hello}
\pagestyle{fancy}

\begin{document}

Lorem ipsum\ldots

\clearpage

Lorem ipsum\ldots

\end{document}

관련 정보