Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to use several different headers and footers in a document. After a lot of trying I have decided to use titleps as the way to go, as I in any case redefine the sections, subsections, etc.

The problem is that I have to move the footrule up, because I have the requirement to add bits that are spread over two lines.

I found that if I use only one page style the redefinition of head- or footrule works, but one must apparently place it after one have selected a pagestyle else its not defined.

Here is an MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{titleps}

\newpagestyle{a}
{\sethead{}{Header-a}{}\headrule
  \setfoot{}{Footer-a}{}\footrule}
\pagestyle{a}

\newpagestyle{b}
{\sethead{}{\parbox{0.4\textwidth}{\centering
Header-b\\Second line}}
{}\headrule
  \setfoot{}{\parbox{0.4\textwidth}{\centering
  Footer-b\\Second line}}
  {}\footrule}

%\pagestyle{b}

\renewcommand\makeheadrule{\color{red}\rule[-1\baselineskip]{\linewidth}{0.4pt}}
\renewcommand\makefootrule{\color{green}\rule[1.2\baselineskip]{\linewidth}{0.8pt}}
\begin{document}
\pagestyle{a}
Page 1
\clearpage
\pagestyle{b}
Page 2
\end{document}

With this I get different headers/footers, but the redefinition of the head/footrule has no effect.

How could one achieve that?

I would only need one definition of it as it would be common to my whole document, but in general there could also be the requirement to change it per pagestyle.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Unfortunately the commands you are trying to redefine are local to a page style, i.e. defining them directly in the preamble will not work because the page style settings will override them.

So, you can redefine those commands each time you change the page style or incorporate them in each page style, which is the best solution.

Rewriting your MWE as:

\documentclass{article}
\usepackage{xcolor}
\usepackage{titleps}

\newpagestyle{a}{%
  \sethead{}{Header-a}{}
  \setfoot{}{Footer-a}{}
  \renewcommand\makeheadrule{\color{red}\rule[-1\baselineskip]{\linewidth}{0.4pt}}
  \renewcommand\makefootrule{\color{green}\rule[1.2\baselineskip]{\linewidth}{0.8pt}}
}

\newpagestyle{b}{%
  \sethead{}{\parbox{0.4\textwidth}{\centering
    Header-b\\Second line}}{}
  \setfoot{}{\parbox{0.4\textwidth}{\centering
    Footer-b\\Second line}}{}
  \renewcommand\makeheadrule{\color{red}\rule[-1\baselineskip]{\linewidth}{0.4pt}}
  \renewcommand\makefootrule{\color{green}\rule[1.2\baselineskip]{\linewidth}{0.8pt}}
}

\begin{document}
\pagestyle{a}
Page 1
\clearpage
\pagestyle{b}
Page 2
\end{document} 

will output the desired result:

enter image description here

share|improve this answer
    
This does the job! –  Louis Aug 13 '13 at 16:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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