1

There's so many small chapters in the book I am publishing, that I've altered the appearance of the ToC. I'm happy with the results, only, I want to add a line to visually separate the mainmatter from the frontmatter and the backmatter chapters. On the left is what I have now, but on the right is what I'm looking for.

enter image description here

MWE:

\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}

With 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 "

and index_style2.ist:

item_0 "\n \\item \\small "

delim_0 " \\Dotfill "
delim_1 " \\Dotfill "
delim_2 " \\Dotfill "
3
  • \addtocontents{toc}{\begin{center}\rule{.8\textwidth}{0.5pt}\end{center}} right after \mainmatter or \backmatter?
    – frabjous
    Sep 22 at 20:43
  • @frabjous Might yo think of turning this into an answer rather than a comment? Sep 23 at 18:54
  • @PeterWilson Done!
    – frabjous
    Sep 23 at 19:32

1 Answer 1

1

You can use the command \addtocontents{toc}{...} to add arbitrary code to the .toc file at a certain point in the document as it's being written.

In your case, I might define a command that could be reused. Using something similar to the code you suggested to produce the rule and center it, this might be something like:

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

You could then use the \inserttocseparator command in your document at the places corresponding to where in the ToC you want to insert a line. As you described what you want, this could be right after \mainmatter and \backmatter:

\mainmatter\inserttocseparator

And

\backmatter\inserttocseparator

The result looks like this:

with center environment

It's a matter of taste, but the center environment produces gaps above and below the lines that are perhaps a bit too big. An alternative might be:

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

The result is more compact:

with par commands

You could play around with \vspace* commands and the like inside the definition of \inserttocseparator if you want to fine tune that.

Here's the full document used to produce the above for reference:

\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}

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.