3

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.

5

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

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

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.