我的索引跳转到页面顶部。我目前正在使用以下代码。
\documentclass[a4paper,11.5pt,twoside, openleft]{book}
\usepackage{titlesec}
\usepackage{imakeidx}
\usepackage{xcolor}
\newcommand{\boldindex}[1]{\textcolor{DarkPurple}{\textbf{#1}}\nouppercase{\index{#1}}}
\makeindex[intoc]
\titleformat{\chapter}[display]{}{}{-2pt}{\hskip5.5cm\centering\Huge \bfseries \mbox}
\titlespacing{\chapter}{0pt}{-120pt}{27pt}
\definecolor{DarkPurple}{RGB}{63, 22, 59}
\begin{document}
\renewcommand\indexname{Begrippen Index}
\boldindex{Test}\\
\boldindex{tEst}\\
\boldindex{teSt}\\
\boldindex{tesT}
\printindex
\end{document}
有人知道如何解决这个问题吗?
答案1
您发布的代码会产生无相关错误,但在book
类中索引标题基本上设置为
\twocolumn[\@makeschapterhead{\indexname}]
因此这会强制新页面使用\chapter*
样式标题,然后将索引设置为两列。这是设计使然,但您可以theindex
以任何您想要的方式定义命令。此外,imakeindex
除非您使用,否则包会强制新页面[nonewpage]
%\documentclass[a4paper,11.5pt,twoside, openleft]{book}
% there is no 11.5 or openleft option
\documentclass[a4paper,11pt,twoside, openany]{book}
\usepackage{titlesec}
\usepackage[nonewpage]{imakeidx}
\usepackage{xcolor}
\newcommand{\boldindex}[1]{\textcolor{DarkPurple}{\textbf{#1}}{\index{#1}}}
\makeindex[intoc]
\titleformat{\chapter}[display]{}{}{-2pt}{\hskip5.5cm\centering\Huge \bfseries \mbox}
\titlespacing{\chapter}{0pt}{-120pt}{27pt}
\makeatletter
\renewenvironment{theindex}
{\section*{index}%
\let\item\@idxitem}
{}
\makeatother
\definecolor{DarkPurple}{RGB}{63, 22, 59}
\begin{document}
\renewcommand\indexname{Begrippen Index}
\boldindex{Test}\\
\boldindex{tEst}\\
\boldindex{teSt}\\
\boldindex{tesT}
\printindex
\end{document}
答案2
\titleformat{name=\chapter, numberless}[block]{}{}{0pt}{\filright \Huge \bfseries}[\vskip4.5pt]
添加代码后问题已解决 。