I need to have different (imposed) pagestyles and thus am using fancyhydr. But I do not succeed to do the index correctly : it should begin on a certain pagestyle (say indextitle) and then have another style (say indexstyle). I do not know how to settle that : if I put the style before the command \printindex, it affects the last page before the index, which I do not want. I have tried to use the afterpage package which works fine for the inextitle page but does not solve the problem for the following pages. I have not found a way to settle the style in imakeidx directly.
Here is a MWE
\documentclass[a4paper,11pt,twoside,openright]{book}
\usepackage[body={110mm, 185mm}, headheight=55pt]{geometry}
\usepackage{imakeidx}
\usepackage{fancyhdr}
\usepackage{afterpage}
\indexsetup{level=\chapter} %
\makeindex
\usepackage[rule=0.6pt, columnsep=20pt, justific=raggedright, font=small]{idxlayout}
\fancypagestyle{indextitle}{%
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead{}
\fancyfoot{}
}
\fancypagestyle{index}{%
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead{}
\fancyhead[CE]{\textit{Index}}
\fancyhead[CO]{\textit{Index}}
\fancyfoot[C]{\thepage}
}
\fancypagestyle{paper}{%
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead{}
\fancyhead[CE]{Name}
\fancyhead[CO]{Title of the paper}
\fancyfoot[C]{\thepage}
}
\begin{document}
\pagestyle{paper}
A text with no sense\index{sense}
Just to make an index\index{index}
\afterpage{\thispagestyle{indextitle}}
\pagestyle{index}
\printindex
\end{document}
One sees that the main page has the wrong header.
I have tried several other things (clearpage first, but then the index begins two pages later). I would like also to change the way the title is done but it may be a different question. Thanks a lot.
Best Answer
The culprit is
idxlayout
that does strange things with the page style for the first page in an index.You can remedy to the problem by issuing
\thispagestyle{indextitle}
before starting to typeset the index.