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}
\documentclass
, the omissions in the preamble trigger the error messageMissing \begin{document}
, and\pagestyle{fancy}
isn't defined.