3

I am working on a book class and need to create a Table of Contents that exactly matches the format shown in the image. I have searched online, but the discussions mainly focus on removing indentation. However, the Part, Chapter, Section, and Subsection titles are still not properly aligned. I would like all of them to be aligned correctly, and I also want to remove the extra space before the title "Table of Contents" in the default ToC. Can anyone help me with this? Table of Contents

\documentclass[9pt, a4paper, twoside]{extbook} \usepackage[german]{babel} % Load babel for German language support \usepackage{minitoc} % For mini-table of contents \usepackage[unicode]{hyperref} % For hyperlinks in the ToC \usepackage{xcolor} % For link colors % Customizations for ToC appearance \hypersetup{ colorlinks=true, linkcolor=blue, % Adjust color as needed citecolor=blue, urlcolor=blue } % Adjust ToC title for German \addto\captionsgerman{\renewcommand{\contentsname}{Inhaltsverzeichnis}} \renewcommand{\mtctitle}{Inhaltsverzeichnis} \dominitoc % Initialize minitoc \begin{document} % Table of Contents setup \tableofcontents % Example chapters and sections \part{Grundlagen der Mathematik, Foundations} \chapter{Introduction} \minitoc % Generates a mini-TOC for this chapter \section{Section One} \subsection{Subsection One} \section{Section Two} \subsection{Subsection Two} \subsection{Subsection Three} \part{Differenzialrechnung} \chapter{Introduction} \minitoc % Generates a mini-TOC for this chapter \section{Section One} \subsection{Subsection One} \section{Section Two} \subsection{Subsection Two} \subsection{Subsection Three} \chapter{Second Chapter} \minitoc % Generates a mini-TOC for this chapter \section{Section One} \subsection{Subsection One} \section{Section Two} \subsection{Subsection Two} \subsection{Subsection Three} \end{document} 
5
  • 4
    Off-topic: Don't use babel with the german option unless you want to adhere to pre-1996 syntax and grammer rules. Else, do use the ngerman option. Commented Jan 2 at 3:41
  • 2
    Please summarize, in words, what some of the main ToC-related formatting requirements are. E.g., which font size should be employed for entries of type part, chapter, etc.? Do you need to adjust the appearance of the "Inhaltsverzeichnis" chapter-level entry, or will you take care of that matter elsewhere? What are entries types that are numbered "I" and "II" in the ToC: Are they part-level or chapter-level entries? Do you need to adjust the appearance of the mini-ToCs as well, in addition to that of the main ToC? Commented Jan 2 at 3:53
  • 1
    And, should there be no page numbers printed next to what I assume are part-level entries? Commented Jan 2 at 4:10
  • @Mico The font size for the title "Inhaltsverzeichnis" is 17 pt, for part title is 12pt, chapter title it is 9.5pt and the section and subsection font size is 8.5pt. Roman numbers "I" and "II" are only for parts. And page numbers of part should not show but for rest it should as you can see in the given image. Commented Jan 2 at 10:23
  • 1
    @SamiaRani Please add all relevant information to the question! And please also focus on one single problem, e.g., either the formatting of the chapter heading of the ToC or the ToC entries or the page header. Commented Jan 2 at 11:37

2 Answers 2

4

It seems these are several question, e.g., about changing the ToC entries and about changing the heading. Here an example using scrbook instead of extbook, because scrbook provides all features needed for changing the ToC and the chapter headings:

\documentclass[fontsize=9pt,toc=flat,toc=chapterentrywithdots,numbers=noenddot,DIV=10]{scrbook} \usepackage[svgnames]{xcolor} \usepackage[colorlinks, linkcolor=DarkBlue]{hyperref} \usepackage[ngerman]{babel} \usepackage{mwe} \usepackage{iftex} \usepackage{libertinus}% Just a guess, because the font looks similar to the one of the screenshot. \usepackage{amsfonts} \usepackage{unicode-math}% I recommend LuaLaTeX! \renewcommand\familydefault{\sfdefault}% Use sf as default (just a guess because all entries in the screenshot seems to be sf) % Change fonts of ToC entries \DeclareTOCStyleEntry[entryformat=\textbf]{default}{section} \DeclareTOCStyleEntry[entryformat=\large\textbf]{default}{chapter} \DeclareTOCStyleEntry[entryformat=\Large\textbf]{default}{part} % Remove page number from ToC entry \DeclareTOCStyleEntry[pagenumberbox=\csname @gobble\endcsname]{default}{part} \addtokomafont{chapter}{\color{DarkCyan}} % \addtokomafont{sectioning}{\boldmath}% optional % Change the formatting of the chapter hadings \RedeclareSectionCommand[beforeskip=0pt]{chapter} \makeatletter \renewcommand*{\chapterlinesformat}[3]{% \@hangfrom{#2}{#3}\par\nobreak \rule{\linewidth}{1pt}% } \makeatother \begin{document} \frontmatter \tableofcontents \mainmatter \part{Grundlagen: Matrizen und lineare Gleichungssysteme} \chapter{Matrizen} \section{Matrizen (Grundlagen)} \subsection{Reelle Matrizen} \subsection{Matrizen auf beliebigen Körpern} \subsection{Die Menge $\mathbb{K}^{m × n}$} \section{Operationen auf Matrizen} \subsection{Addition und Substraktion von Matrizen} \chapter{Lineare Gleichungssysteme} \end{document} 

ToC with flat formatting of the entries

Feel free to use other font sizes than \large and \Large, e.g., absolute sizes using \fontsize{…}{…}, e.g., \fontsize{17}{20}.

For more information about options toc=flat, toc=chapterentrywithdots and the used commands \DeclareTOCStyleEntry, \RedeclareSectionCommand and how to redefine \chapterlinesformat see the KOMA-Script documentation (available in English and German) and also the KOMA-Script Wiki (also available in English and German).

Note: If you insist in staying with class extbook instead of switching to scrbook you still can use \DeclareTOCEntryStyle if you add package scrextend. But in this case, you would need to use \DeclareTOCEntryStyle also to change the indent and numwidth to configure the flat style manually. However in this case you'd still have an issue with part entries, because these are not using \numberline. See my answer to Issue with aligning part numbers and titles in ToC using tocloft for more information about the needed configuration with book or extbook and how to patch \@part to solve the \numberline problem. So with extbook you would need something like:

\documentclass[9pt,a4paper]{extbook} \usepackage[svgnames]{xcolor} \usepackage[ngerman]{babel} \usepackage{mwe} \usepackage{iftex} \usepackage{libertinus}% Just a guess, because the font looks similar to the one of the screenshot. \usepackage{amsfonts} \usepackage{unicode-math}% I recommend LuaLaTeX! \usepackage{tocbasic} \renewcommand\familydefault{\sfdefault}% Use sf as default (just a guess because all entries in the screenshot seems to be sf) % Change indent of entries \DeclareTOCStyleEntries[indent=0pt,numwidth=25pt]{tocline}{part,chapter,section,subsection} % Change fonts of ToC entries (and add dots to the chapter entries) \DeclareTOCStyleEntry[entryformat=\textbf]{tocline}{section} \DeclareTOCStyleEntry[entryformat=\large\textbf,linefill=\TOCLineLeaderFill]{tocline}{chapter} \DeclareTOCStyleEntry[entryformat=\Large\textbf]{tocline}{part} % Make it work also for part entries \usepackage{xpatch} \makeatletter \xpatchcmd{\@part}{% \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}% }{% \addcontentsline{toc}{part}{\numberline{\thepart}#1}% }{\typeout{\string\@part\space patch successfull}}{\PaTchFailue} \DeclareTOCStyleEntry[pagenumberbox=\@gobble]{tocline}{part} \makeatother \usepackage[colorlinks, linkcolor=DarkBlue]{hyperref}% Load it as late a possible! \begin{document} \frontmatter \tableofcontents \mainmatter \part{Grundlagen: Matrizen und lineare Gleichungssysteme} \chapter{Matrizen} \section{Matrizen (Grundlagen)} \subsection{Reelle Matrizen} \subsection{Matrizen auf beliebigen Körpern} \subsection{Die Menge $\mathbb{K}^{m × n}$} \section{Operationen auf Matrizen} \subsection{Addition und Substraktion von Matrizen} \chapter{Lineare Gleichungssysteme} \end{document} 

to change the ToC entries.

flat TOC entries using extbook

An additional package like titlesec would be needed to change the chapter headings (but this would IMHO be another question). So it is usually much easier to use a configurable class like scrbook.

Note: I've not changed the page header, because this would be a completely different question. If you need such changes too, please have a look into the scrlayer-scrpage chapters in the KOMA-Script documentation and the Wiki or ask a new question.

Note: extbook is derived from a very old version of standard class book. No one of the changes in book from the last 25 years have been inherited to extbook.

3
  • If I change "extbook" to "scrbook" then all other settings for the the book are changed. Is this only solution for toc? Commented Jan 2 at 10:58
  • 1
    @SamiaRani Without knowing, which settings are changed, I cannot tell you, how to change them back. KOMA-Script classes are very configurable, so you should be able to change it, e.g., using options like chapterprefix (in this case, you would need to redefine \chapterlineswithprefixformat instead of \chapterlinesformat (see the documentation and ask a new question if this does not help). For staying with extbook see my note and also the linked question and answer. Commented Jan 2 at 11:04
  • 1
    @SamiaRani I've added an additional extbook example using the information from the linked answer. But next time please first read linked question. Commented Jan 2 at 11:35
3

My main recommendation would be to employ a more capable document class than the book/extbook document class. Two such candidates are memoir and scrbook.

If you're stuck with book/extbook, the set of adjustments you can make to the appearance to the ToC is somewhat limited -- short of rewriting major parts of the book document class code, of course. In the following, I suggest how to employ the machinery of the tocloft package to adjust the indentation amounts for entries of type chapter, section, and subsection. (Unfortunately, the book class doesn't provide a good "hook" for modifying important components, such as indentation amounts, of the appearance of part-level entries in the ToC.)

I also suggest how to

  • suppress the showing of page numbers for part-level entries,
  • add dot leaders for chapter-level entries, and
  • remove the extra whitespace above the chapter-level header "Inhaltsverzeichnis".
  • About making elements of the ToC into hypertargets: I'd avoid making the ToC look resemble a colorful Christmas tree. If you must show hypertargets, I'd use the page numbers for this purpose.

How to modify the appearance of chapter-level headers should be the topic for a separate question.

enter image description here

\documentclass[9pt, a4paper, twoside]{extbook} \usepackage{iftex} \ifpdftex\usepackage[T1]{fontenc}\fi \usepackage[ngerman]{babel} % German language support \usepackage{minitoc} % for mini-ToC \usepackage{xcolor} % for named colors % Adjust ToC titles for German %% \addto\captionsgerman{% %% \renewcommand{\contentsname}{Inhaltsverzeichnis}} \renewcommand{\mtctitle}{Inhaltsverzeichnis} \dominitoc % Initialize minitoc \usepackage{hyperref} % For hyperlinks \hypersetup{colorlinks=true,allcolors=blue, linktocpage} % use page numbers as hypertargets % modify appearance of ToC \usepackage{tocloft} %%\cftsetindents{part}{0em}{3em} % doesn't work (see text) \cftsetindents{chap}{0em}{3em} % no indentation \cftsetindents{sec}{0em}{3em} \cftsetindents{subsec}{0em}{3em} \cftsetindents{subsubsec}{0em}{3em} % in case you set '\setcounter{tocdepth}{3}' \cftpagenumbersoff{part} % don't display page numbers of part-level entries \renewcommand{\cftchapleader}{\mdseries\cftdotfill{\cftdotsep}} \renewcommand\cftchappagefont{\mdseries} % optional \begin{document} % generate the ToC \vspace*{-50pt} % this adjustment is specific to 'book' class \tableofcontents % Example parts, chapters, sections, and subsections \part{Grundlagen der Mathematik} \chapter{Introduction} \minitoc % generate a mini-ToC \section{Section One} \subsection{Subsection One} \section{Section Two} \subsection{Subsection Two} \subsection{Subsection Three} \part{Differenzialrechnung} \chapter{Introduction} \minitoc % generate a mini-ToC \section{Section One} \subsection{Subsection One} \section{Section Two} \subsection{Subsection Two} \subsection{Subsection Three} \chapter{Second chapter of Part II} \minitoc % generate a mini-ToC \section{Section One} \subsection{Subsection One} \section{Section Two} \subsection{Subsection Two} \subsection{Subsection Three} \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.