6

The title is self-explanatory.

In my document's current state, I get this rendering result after compiling with XeLaTeX :

result

Here's a MWE of which packages and commands I use to obtain my current header style :

\documentclass{report}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}

\usepackage{lipsum}% http://www.ctan.org/tex-archive/macros/latex/contrib/lipsum

\usepackage{titlesec}
\usepackage{xcolor}


\renewpagestyle{plain}[\small\sffamily\upshape\color{red}]{
    \headrule
    \sethead{\chaptertitle}{}{Université de la Rochelle}
}


\author{ME}
\title{Bash report}

\pagestyle{plain}
\begin{document}
\maketitle

\tableofcontents
\thispagestyle{empty}

\chapter{Matrices de convolution}
\lipsum

\lipsum
\end{document}

What I actually would like is to color "red" the lines created by the header and footer.

2 Answers 2

6

titlesec defines helper macros to set up the lines, this drops red into the head line

enter image description here

\documentclass{report}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}

\usepackage{lipsum}% http://www.ctan.org/tex-archive/macros/latex/contrib/lipsum

\usepackage{titlesec}
\usepackage{xcolor}

\makeatletter

\newcommand\setheadrule[1]{%
  \ifdim#1=\z@
    \let\makeheadrule\@empty
  \else
    \def\makeheadrule{{\color{red}\rule[-.3\baselineskip]{\linewidth}{#1}}}%
  \fi}

\makeatother


\renewpagestyle{plain}[\small\sffamily\upshape]{
    \headrule
    \sethead{\chaptertitle}{}{Universite de la Rochelle}
}


\author{ME}
\title{Bash report}

\pagestyle{plain}
\begin{document}
\maketitle

\tableofcontents
\thispagestyle{empty}

\chapter{Matrices de convolution}
\lipsum

\lipsum
\end{document}

The foot rule command is by default

\newcommand\setfootrule[1]{%
  \ifdim#1=\z@
    \let\makefootrule\@empty
  \else
    \def\makefootrule{\rule[.7\baselineskip]{\linewidth}{#1}}%
  \fi}

But not apparently used in this MWE so I didn't change it/

2
  • I have an error if I insert the hack that you wrote in my current document state, I get the following compilation error (using XeLaTeX) : ! LaTeX Error: Command \setheadrule already defined. Or name \end... illegal, see p.192 of the manual.
    – vdegenne
    Commented Feb 22, 2013 at 20:31
  • I just added [pagestyles] to the \usepackage{titlesec} inclusion, works fine now.
    – vdegenne
    Commented Feb 22, 2013 at 20:38
2

I solved the problem by slightly modifying David's code:

\makeatletter
\renewcommand\setheadrule[1]{%
  \ifdim#1=\z@
    \let\makeheadrule\@empty
  \else
    \def\makeheadrule{{\color{red}\rule[-.3\baselineskip]{\linewidth}{#1}}}%
  \fi}
\makeatother

Using David's code, I had the same error message reported by vdegenne in his first comment (solved by him by adding the pagestyles option to the titlesec package as said in his second comment). Since their solution did not work for me, I worked out my own by just substituting \renewcommand instead of \newcommand in Dave's code: this simply redefines the command avoiding any "already defined!" run time error, and produces the sought for graphical output.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .