[Tex/LaTex] Set header and footer rule color in memoir

colorheader-footermemoir

Is there a way to set color for header and footer rule in memoir class?

Using the following code:

\documentclass[ebook,12pt,twoside,openany]{memoir}

\usepackage{lipsum}
\usepackage{graphicx}


\usepackage[english,italian]{babel}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}

\usepackage[dvipsnames]{xcolor}  % Allows the definition of hex colors

\newenvironment{dedication}
{
   \cleardoublepage
   \thispagestyle{empty}
   \vspace*{    \stretch{1}}
   \hfill    \begin{minipage}[t]{0.66    \textwidth}
   \raggedright
}%
{
   \end{minipage}
   \vspace*{    \stretch{3}}
   \clearpage
}


\setlength{    \topmargin}{-0.5in}
\setlength{    \textheight}{520pt}


\makepagestyle{myruled}
\makeheadrule {myruled}{    \textwidth}{    \normalrulethickness}
\makefootrule {myruled}{    \textwidth}{    \normalrulethickness}{    \footruleskip}
\makeevenhead {myruled}{}{    \small    \itshape    \leftmark} {}
\makeoddhead {myruled}{}{    \small    \itshape    \rightmark}{}
\makeevenfoot {myruled}{    \small      \thepage}{}{} 
\makeoddfoot {myruled}{}{} {    \small      \thepage}
\makeatletter % because of     \@chapapp
\makepsmarks {myruled}{
\nouppercaseheads
\createmark {chapter} {both} {nonumber}{    \@chapapp    \ }{.     \ }
\createmark {section} {right}{shownumber}{} {.     \ }
\createmark {subsection} {right}{shownumber}{} {.     \ }
\createmark {subsubsection}{right}{shownumber}{} {.     \ }
\createplainmark {toc} {both} {    \contentsname}
\createplainmark {lof} {both} {    \listfigurename}
\createplainmark {lot} {both} {    \listtablename}
\createplainmark {bib} {both} {    \bibname}
\createplainmark {index} {both} {    \indexname}
\createplainmark {glossary} {both} {    \glossaryname}
}
\makeatother
\setsecnumdepth{subsubsection}

\begin{document}


\begin{dedication}
Put dedication here
\end{dedication}

\chapterstyle{thatcher}

\pagestyle{myruled}

\chapter{Lipsum chapter}

\lipsum[1-8]

\end{document}

After loading xcolor packages I tried using \color{colorname} command but while it works for text it won't work when put before or after \makeheadrule or \makefootrule.

Best Answer

You can use

\makeheadfootruleprefix{<style>}{<for headrule>}{<for footrule>}

An example:

\documentclass[ebook,12pt,twoside,openany]{memoir}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[english,italian]{babel}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage[dvipsnames]{xcolor}  % Allows the definition of hex colors

\newenvironment{dedication}
{
   \cleardoublepage
   \thispagestyle{empty}
   \vspace*{\stretch{1}}
   \hfill\begin{minipage}[t]{0.66\textwidth}
   \raggedright
}%
{
   \end{minipage}
   \vspace*{\stretch{3}}
   \clearpage
}

\setlength{\topmargin}{-0.5in}
\setlength{\textheight}{520pt}

\makepagestyle{myruled}
\makeheadfootruleprefix{myruled}{\color{Bittersweet}}{\color{PineGreen}}
\makeheadrule{myruled}{\textwidth}{\normalrulethickness}
\makefootrule{myruled}{\textwidth}{\normalrulethickness}{\footruleskip}
\makeevenhead{myruled}{}{\small\itshape\leftmark}{}
\makeoddhead{myruled}{}{\small\itshape\rightmark}{}
\makeevenfoot{myruled}{\normalcolor\small\thepage}{}{} 
\makeoddfoot{myruled}{}{}{\normalcolor\small\thepage}
\makeatletter % because of \@chapapp
\makepsmarks{myruled}{
\nouppercaseheads
\createmark{chapter}{both}{nonumber}{\@chapapp\ }{. \ }
\createmark{section}{right}{shownumber}{}{. \ }
\createmark{subsection}{right}{shownumber}{}{. \ }
\createmark{subsubsection}{right}{shownumber}{}{. \ }
\createplainmark{toc}{both}{\contentsname}
\createplainmark{lof}{both}{\listfigurename}
\createplainmark{lot}{both}{\listtablename}
\createplainmark{bib}{both}{\bibname}
\createplainmark{index}{both}{\indexname}
\createplainmark{glossary}{both}{\glossaryname}
}
\makeatother
\setsecnumdepth{subsubsection}

\begin{document}

\begin{dedication}
Put dedication here
\end{dedication}

\chapterstyle{thatcher}

\pagestyle{myruled}

\chapter{Lipsum chapter}

\lipsum[1-8]

\end{document}

Notice the use of \normalcolor inside \makeevenfood and \makeoddfoot to prevent the page number to also receive color (remove \normalcolor of you want the number to be also colorized).

An image of one of the pages obtained:

enter image description here

Related Question