[Tex/LaTex] Can’t change the colour of the line in the header (fancyhdr)

colorfancyhdrrules

I'm trying to change the colour of the line in my header to the grey, and I don't know how to do it correctly.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}  % Включаем пакет для поддержки русского
\usepackage[a4paper, portrait, margin=1in, hmargin=1.3cm, top=4cm, bottom=4cm, headheight=3cm, footskip=2.5cm]{geometry}
%\usepackage[tiny]{titlesec}
\usepackage{fancyhdr}
\usepackage{tabu}
\usepackage{xcolor}
% not sure is it a right command
%    \newcommand\setheadrule[1]{%
%        \def\makeheadrule{{\color{ grey}\rule[-.3\baselineskip]%{\linewidth}{#1}}}%
%    }

    \fancypagestyle{prefirstpage}
    {
    \rhead{
    \hline
    \begin{tabu} to \textwidth { |X[0.15,l,p]|X[0.25,l,p]|X[0.25,l,p]|X[0.4,l,p]|}
    \taburulecolor{gray}
      & \multicolumn{2}{l|}{Adress} &   \\ [10ex] \hline
      & \textbf{№ УКД:} & \textbf{ Версия:}  & \textbf{Страниц:}  \\ \hline
    \end{tabu}
%not sure is it right command
%    \setheadrule{}
    }
    }
    \begin{document}
    \pagestyle{prefirstpage}

    \end{document}

enter image description here

What I want to have is:
enter image description here

Best Answer

The fancyhdr package already provides support for headrules with \headrule and \headrulewidth. The colour is a little bit tricky, but can be used as well by storing the old code in a \oldheadrule command and using {\color{\headrulecolour}\oldheadrule}} (note the grouping {})

There is a clear warning about headheight being too small, that's why I increased it.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}  % Включаем пакет для поддержки русского
\usepackage[a4paper, portrait, margin=1in, hmargin=1.3cm, top=5.5cm, bottom=4cm, headheight=125pt, footskip=2.5cm]{geometry}
\usepackage{fancyhdr}
\usepackage{tabu}
\usepackage[svgnames,x11names,dvipsnames]{xcolor}

\providecommand{\copyid}{4711}
\providecommand{\varVersion}{3.14159}

\newcommand{\headrulecolour}{white!70!black}
\renewcommand{\headrulewidth}{.1\baselineskip}

\let\oldheadrule\headrule

\fancypagestyle{prefirstpage}
{
  \rhead{%
    \begin{tabu} to \textwidth { |X[0.15,l,p]|X[0.25,l,p]|X[0.25,l,p]|X[0.4,l,p]|}
      \hline
      \taburulecolor{gray}
      & \multicolumn{2}{l|}{Adress} &   \\ [10ex] \hline
      & \textbf{№ УКД:} \copyid{}  & \textbf{ Версия:} \varVersion{} & \textbf{Страниц:}  \\ \hline
    \end{tabu}
  }
  \renewcommand{\headrule}{{\color{\headrulecolour}\oldheadrule}}%
}

\begin{document}
\pagestyle{prefirstpage}
.
\end{document}

enter image description here