2

I use makeidx package to create an index, but some index items fail to be located in the right pages.

For example, an index in 1st page of body text will be located to the cover after clicking the hyperlink, but the index in later pages, like 100th page, will be located normally.

This is the original code, using XeLaTex to compile:

\documentclass[a4paper,12pt,twoside]{book}
\usepackage[CJKchecksingle,CJKnumber]{xeCJK}
\usepackage[top=1in,bottom=1in,left=1.25in,right=1.25in,columnsep=25pt]{geometry}
\usepackage{setspace}
\usepackage{fontspec}
\usepackage{type1cm}
\usepackage{enumitem}
\usepackage[toc]{multitoc}
\usepackage{multicol}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{fancyhdr}
\usepackage{makeidx}
\usepackage[CJKbookmarks=true,bookmarksnumbered,bookmarksopen=false,pdfencoding=auto,colorlinks=true,linkcolor=black,urlcolor=magenta,hyperindex=true]{hyperref}

%fonts
\setmainfont{Times New Roman}

%contents style
\renewcommand{\contentsname}{aaaa}
\setcounter{tocdepth}{1}

%section style
\titleformat{\chapter}{\centering\LARGE\bfseries}{}{}{}
\titleformat{\section}{\centering\Large\bfseries}{}{}{}
\titleformat{\subsection}{\flushleft\LARGE\itshape}{}{}{}

%cancelling numbering the section
\makeatletter
\newcommand\specialsectioning{\setcounter{secnumdepth}{-2}}
\makeatother

%page style
\fancyhead[LO]{\nouppercase\leftmark}
\fancyhead[RO]{\nouppercase\rightmark}
\fancyhead[LE]{\nouppercase\rightmark}
\fancyhead[RE]{\nouppercase\leftmark}
\renewcommand{\headrulewidth}{0.4pt}
\fancyfoot[C]{\thepage}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}

%separation rule between columns
\setlength\columnseprule{0.4pt}

%entry format
\newcommand{\entry}[3]{\subsection{#1}\noindent\textbf{#2}\index{#2!#1}\\ {#3}} % Defines the command to print each word on the page

%adjust item separation
\setenumerate[1]{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=0pt}
\setitemize[1]{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=0pt}


%index
\renewcommand{\indexname}{my\_index}
\makeindex

\begin{document}
\title{aaa}
\author{aaa}
\date{aaa}
\maketitle{aaa}
\thispagestyle{empty}
\cleardoublepage

\onehalfspacing

\frontmatter
\pagestyle{plain}
\tableofcontents

\mainmatter
\pagestyle{fancy}
\cleardoublepage
\phantomsection

\specialsectioning
\chapter{aaa}

\begin{multicols}{2}
\section{aaa}
\entry{aaa}{aaa}
{
aaa
\begin{enumerate}[label=\arabic*,leftmargin=*]
  \item blabla
  \item blabla
\end{enumerate}
}

\end{multicols} 

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{\indexname}
\printindex

\end{document}
  • 1
    welcome to tex.sx. please make this example compilable. it lacks a \documentclass, the omissions in the preamble trigger the error message Missing \begin{document}, and \pagestyle{fancy} isn't defined. – barbara beeton May 18 '16 at 13:57
  • Thx for reminding. Code is compilable now. – lizhe May 18 '16 at 14:46
2

The problem is that you have two pages numbered 1, even if the first has no visible numbering: before \frontmatter the numbering is the default, that is arabic. You can solve the issue by assigning a different numbering style to the title page:

\documentclass[a4paper,12pt,twoside]{book}
\usepackage[CJKchecksingle,CJKnumber]{xeCJK}
\usepackage[top=1in,bottom=1in,left=1.25in,right=1.25in,columnsep=25pt]{geometry}
\usepackage{setspace}
\usepackage{fontspec}
\usepackage{type1cm}
\usepackage{enumitem}
\usepackage[toc]{multitoc}
\usepackage{multicol}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{fancyhdr}
\usepackage{makeidx}
\usepackage[CJKbookmarks=true,bookmarksnumbered,bookmarksopen=false,pdfencoding=auto,colorlinks=true,linkcolor=black,urlcolor=magenta,hyperindex=true]{hyperref}

%fonts
\setmainfont{Times New Roman}

%contents style
\renewcommand{\contentsname}{aaaa}
\setcounter{tocdepth}{1}

%section style
\titleformat{\chapter}{\centering\LARGE\bfseries}{}{}{}
\titleformat{\section}{\centering\Large\bfseries}{}{}{}
\titleformat{\subsection}{\flushleft\LARGE\itshape}{}{}{}

%cancelling numbering the section
\makeatletter
\newcommand\specialsectioning{\setcounter{secnumdepth}{-2}}
\makeatother

%page style
\fancyhead[LO]{\nouppercase\leftmark}
\fancyhead[RO]{\nouppercase\rightmark}
\fancyhead[LE]{\nouppercase\rightmark}
\fancyhead[RE]{\nouppercase\leftmark}
\renewcommand{\headrulewidth}{0.4pt}
\fancyfoot[C]{\thepage}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}

%separation rule between columns
\setlength\columnseprule{0.4pt}

%entry format
\newcommand{\entry}[3]{\subsection{#1}\noindent\textbf{#2}\index{#2!#1}\\ {#3}} % Defines the command to print each word on the page

%adjust item separation
\setenumerate[1]{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=0pt}
\setitemize[1]{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=0pt}


%index
\renewcommand{\indexname}{my\_index}
\makeindex

\begin{document}

\pagenumbering{Alph} % to keep hyperref happy

\title{aaa}
\author{aaa}
\date{aaa}
\maketitle{aaa}
\thispagestyle{empty}
\cleardoublepage

\onehalfspacing

\frontmatter
\pagestyle{plain}
\tableofcontents

\mainmatter
\pagestyle{fancy}
\cleardoublepage
\phantomsection

\specialsectioning
\chapter{aaa}

\begin{multicols}{2}
\section{aaa}
\entry{aaa}{aaa}
{
aaa
\begin{enumerate}[label=\arabic*,leftmargin=*]
  \item blabla
  \item blabla
\end{enumerate}
}

\end{multicols} 

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{\indexname}
\printindex

\end{document}

Now the index entry will point to page 1.

  • Thx. Problem solved perfectly. – lizhe May 18 '16 at 22:43

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.