在目录中添加分隔线

在目录中添加分隔线

我要出版的书中有很多小章节,所以我改变了目录的外观。我对结果很满意,只是我想添加一条线来在视觉上将目录与章节分开mainmatterfrontmatter左边backmatter是我现在拥有的,但右边是我想要的。

在此处输入图片描述

梅威瑟:

\documentclass[10pt, paper=156mm:235mm, BCOR=12mm, headings=optiontotocandhead, headings=openany]{scrbook}
\KOMAoptions{headings=small}
\usepackage[hidelinks]{hyperref}

\DeclareTOCStyleEntry[
  beforeskip=.4em plus 1pt,
  pagenumberformat=\textbf,
  linefill={\Dotfill},
]{tocline}{chapter}

\makeatletter
\newcommand{\Dotfill}{\leavevmode \leaders \hb@xt@ 0.75em{\hss .\hss }\hfill \kern  \z@}
\makeatother

\usepackage[splitindex]{imakeidx}%Indexing package
\makeindex[intoc,options= -s index_style.ist,name=m,title=\mbox{Index},columns=2]
\makeindex[options= -s index_style2.ist, intoc,name=r,title=\mbox{Appendix A: Initial Publication \& Grouping of Lectures},columns=1]

\usepackage[T1]{fontenc}
\usepackage{Alegreya,AlegreyaSans} 
\renewcommand*\oldstylenums[1]{{\AlegreyaOsF #1}}

\usepackage[toc]{glossaries}
\newglossary*{contemp}{Murids from Inayat Khan's Time}
\newglossary*{list}{List of Persons, Places, Works, etc.}

\makeglossaries

\newglossaryentry{adab}
    {
        name=adab,
        description={Arabic, Persian, Urdu, good manners, politeness, respect},
        text=\emph{adab},
        sort=adab
    }
\newglossaryentry{Akbar}
    {
        name={Akbar, aka Akbar the Great},
        description={(1542–1605) \ldots},
        text=Akbar,
        sort=Akbar,
        type=list
    }
\newglossaryentry{allen}
    {
        name={Allen, Lillian},
        description={An English pupil from the early London period.  She lived in Southampton, UK where there was a Sufi Centre and her address appears in Inayat Khan’s address books for the UK},
        type=contemp,
        text=Lillian Allen,
        sort=Allen Lillian
    }

\begin{document}
\frontmatter
\newpage
\tableofcontents
    \begin{center}
        \rule{.8\textwidth}{0.5pt}
        \rule{.8\textwidth}{0.5pt}
    \end{center}
\addchap{Preface}

\mainmatter
\addchap{There Are Over 100 Chapters} \gls{allen}
\addchap{In This Book} \gls{Akbar}
\addchap{That's Why I Wanted Them} \gls{adab}
\addchap{This Close to Each Other} \index[m]{indexitem}
\addchap{In the Table of Content} \index[r]{other kind of index}

\backmatter
\newpage
\printindex[r]\label{appendix}
\printglossary[toctitle=\mbox{Glossary of Foreign Words}, nonumberlist]
\printglossary[type=list, toctitle=\mbox{List of Persons, Places, Works, etc.}]
\printglossary[type=contemp, toctitle=\mbox{Mureeds from Inayat Khan's Time}, nonumberlist]
\printindex[m]

\end{document}

index_style.ist

headings_flag 1

heading_prefix "\n\\raggedright\\large\\sffamily\\normalfont%
\\noindent\\textbf{"heading_suffix "}\\par\\nopagebreak\n"

item_0 "\n \\item \\small "

delim_0 " \\Dotfill "
delim_1 " \\Dotfill "
delim_2 " \\Dotfill "

index_style2.ist

item_0 "\n \\item \\small "

delim_0 " \\Dotfill "
delim_1 " \\Dotfill "
delim_2 " \\Dotfill "

答案1

您可以使用该命令\addtocontents{toc}{...}在文档写入时将任意代码添加到 .toc 文件的某个位置。

在您的例子中,我可能会定义一个可以重复使用的命令。使用类似于您建议的代码来生成规则并将其居中,这可能是这样的:

\newcommand{\inserttocseparator}{%
    \addtocontents{toc}{\begin{center}\rule{.8\textwidth}{0.5pt}\end{center}}
}

然后,您可以\inserttocseparator在文档中与目录中要插入行的位置相对应的位置使用该命令。正如您所描述的那样,这可能紧跟在\mainmatterand之后\backmatter

\mainmatter\inserttocseparator

\backmatter\inserttocseparator

结果如下:

与中心环境

这是个人喜好问题,但center环境产生的线上方和下方的间隙可能有点太大。另一种选择可能是:

\newcommand{\inserttocseparator}{%
    \addtocontents{toc}{\par\hspace*{0.1\textwidth}\rule{0.8\textwidth}{0.5pt}\par}
}

结果更加紧凑:

使用 par 命令

如果您想对其进行微调,您可以\vspace*在定义中使用命令等进行尝试。\inserttocseparator

以下是用于生成上述内容的完整文档,供参考:

\documentclass[10pt, paper=156mm:235mm, BCOR=12mm, headings=optiontotocandhead, headings=openany]{scrbook}
\KOMAoptions{headings=small}
\usepackage[hidelinks]{hyperref}

\DeclareTOCStyleEntry[
  beforeskip=.4em plus 1pt,
  pagenumberformat=\textbf,
  linefill={\Dotfill},
]{tocline}{chapter}

\makeatletter
\newcommand{\Dotfill}{\leavevmode \leaders \hb@xt@ 0.75em{\hss .\hss }\hfill \kern  \z@}
\makeatother

\usepackage[splitindex]{imakeidx}%Indexing package
\makeindex[intoc,options= -s index_style.ist,name=m,title=\mbox{Index},columns=2]
\makeindex[options= -s index_style2.ist, intoc,name=r,title=\mbox{Appendix A: Initial Publication \& Grouping of Lectures},columns=1]

\usepackage[T1]{fontenc}
\usepackage{Alegreya,AlegreyaSans} 
\renewcommand*\oldstylenums[1]{{\AlegreyaOsF #1}}

\usepackage[toc]{glossaries}
\newglossary*{contemp}{Murids from Inayat Khan's Time}
\newglossary*{list}{List of Persons, Places, Works, etc.}

\makeglossaries

\newglossaryentry{adab}
    {
        name=adab,
        description={Arabic, Persian, Urdu, good manners, politeness, respect},
        text=\emph{adab},
        sort=adab
    }
\newglossaryentry{Akbar}
    {
        name={Akbar, aka Akbar the Great},
        description={(1542–1605) \ldots},
        text=Akbar,
        sort=Akbar,
        type=list
    }
\newglossaryentry{allen}
    {
        name={Allen, Lillian},
        description={An English pupil from the early London period.  She lived in Southampton, UK where there was a Sufi Centre and her address appears in Inayat Khan’s address books for the UK},
        type=contemp,
        text=Lillian Allen,
        sort=Allen Lillian
    }

\newcommand{\inserttocseparator}{%
    \addtocontents{toc}{\par\hspace*{0.1\textwidth}\rule{0.8\textwidth}{0.5pt}\par}
}

\begin{document}
\frontmatter
\newpage
\tableofcontents

\addchap{Preface}

\mainmatter\inserttocseparator
\addchap{There Are Over 100 Chapters} \gls{allen}
\addchap{In This Book} \gls{Akbar}
\addchap{That's Why I Wanted Them} \gls{adab}
\addchap{This Close to Each Other} \index[m]{indexitem}
\addchap{In the Table of Content} \index[r]{other kind of index}

\backmatter\inserttocseparator
\newpage
\printindex[r]\label{appendix}
\printglossary[toctitle=\mbox{Glossary of Foreign Words}, nonumberlist]
\printglossary[type=list, toctitle=\mbox{List of Persons, Places, Works, etc.}]
\printglossary[type=contemp, toctitle=\mbox{Mureeds from Inayat Khan's Time}, nonumberlist]
\printindex[m]

\end{document}

相关内容