2

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

  • As usual: Your example is not compilable:-( Which rule shall be changed? The table rule or the fancyhdr rules? You write of header but the title speaks of footer? – user31729 Mar 22 '16 at 10:37
  • @ChristianHupfer rule in the header – Lucky_girl Mar 22 '16 at 10:44
  • You just edited the title, but the error is still in the code! – user31729 Mar 22 '16 at 10:46
4

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

  • Thanks, but right now it looks like a big black line in the header. – Lucky_girl Mar 22 '16 at 11:02
  • How to make it slim grey? – Lucky_girl Mar 22 '16 at 11:02
  • @Lucky_girl: You defined it to be grey and the thickness is from your .3\baselineskip command --> all is from your settings! There is predefined colour named grey, but Grey which is pretty dark. You can use white!70!black to setup a light gray colour, however – user31729 Mar 22 '16 at 11:04
  • @ChristianHupher How to make it slimmer? If I'm putting values .0.5\baselineskip - it just breaks. – Lucky_girl Mar 22 '16 at 11:08
  • @Lucky_girl: 0.5\baselineskip is even bigger! See my edit, please! – user31729 Mar 22 '16 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.