4

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.

Page of text with 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.

4
  • \afterpage{\pagestyle{indexstyle}\thispagestyle{indextitle}}
    – cfr
    Feb 28, 2017 at 0:55
  • 1
    Does \indexsetup{firstpagestyle=indextitle} help?
    – user31729
    Feb 28, 2017 at 0:56
  • @cfr : Thank you, I had tried variants of this (and now these) and it works for the index, but the style of the last page before the index is then changed (as the indexstyle). This defeats me.
    – Catherine
    Feb 28, 2017 at 17:58
  • @Christian Hupfer : idem...
    – Catherine
    Feb 28, 2017 at 17:58

1 Answer 1

3

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.

\documentclass[a4paper,11pt,twoside,openright]{book}
\usepackage[body={110mm, 185mm}, headheight=55pt]{geometry}  
\usepackage{imakeidx}  
\usepackage{fancyhdr}

\makeindex[columnsep=20pt,columnseprule]

\indexsetup{
  %level=\chapter,% <-- already default
  othercode={%
    \thispagestyle{indextitle}%
    \setlength{\columnseprule}{0.6pt}
    \small\raggedright
  }
}

\fancypagestyle{indextitle}{%
  \renewcommand{\headrulewidth}{0pt}%
  \renewcommand{\footrulewidth}{0pt}%
  \fancyhf{}%
}
\fancypagestyle{index}{%
  \renewcommand{\headrulewidth}{0pt}%
  \renewcommand{\footrulewidth}{0pt}%
  \fancyhf{}%
  \fancyhead[C]{\textit{Index}}%
  \fancyfoot[C]{\thepage}%
} 

\fancypagestyle{paper}{%
  \renewcommand{\headrulewidth}{0pt}%
  \renewcommand{\footrulewidth}{0pt}%
  \fancyhf{}%
  \fancyhead[CE]{Name}%
  \fancyhead[CO]{Title of the paper}%
  \fancyfoot[C]{\thepage}%
} 


\pagestyle{paper}

\begin{document}

A text with no sense\index{sense}

Just to make an index\index{index}

\count255=0
\loop\ifnum\count255<200 \advance\count255 1
\expandafter\index\expandafter{\romannumeral\count255 }
\repeat

\cleardoublepage
\pagestyle{index}
\printindex

\end{document}

enter image description here

4
  • Argh! Perfect, it works. Thank you so much ! I have to read more carefully idxlayout because the solution defeats me.
    – Catherine
    Feb 28, 2017 at 18:00
  • @Oups, I should have said: it almost works. There is a pagenumber in the middle of the first page of the index and it should not be here in my style.
    – Catherine
    Mar 6, 2017 at 17:28
  • @Catherine As I said, the problem is with idxlayout. Updated avoiding it.
    – egreg
    Mar 6, 2017 at 18:31
  • Perfect! It is sad because idxlayout seemed easy to use. I have found a possible solution in another question, changing plain to empty (\let\ps@plain\ps@empty): it works with idxlayout, but of course may lead to other problems if one needs a real "plain format". Your solution is the best, thanks.
    – Catherine
    Mar 7, 2017 at 14:40

You must log in to answer this question.

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