我使用 makeidx 包创建索引,但某些索引项无法定位到正确的页面。
比如正文第1页的索引,点击超链接后会定位到封面,但是后面页面,比如第100页的索引会正常定位。
这是原始代码,使用 XeLaTex 进行编译:
\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
问题是您有两页编号为 1,即使第一页没有可见的编号:\frontmatter
编号之前是默认的,即arabic
。您可以通过为标题页分配不同的编号样式来解决此问题:
\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}
现在索引条目将指向第 1 页。