2

I have to write an Exposé which needs to contain a second table of contents within a section in the document. The requirements are basically the same as already discussed in this question, with the difference, that i not only need \section and \subsection but also \subsubsection.

Edit: It seems that my question was not detailed enough, because it was closed as it was already answered elsewhere. The linked question was about the same TOC multiple times. I do need a separate TOC with individual headings not connected to the current document. The TOC needs to be the TOC of a future document, so it must not refer to any regular headings of the current one.

\documentclass[]{scrartcl}

\begin{document}
\tableofcontents

\section{Introduction}
    Lorem ipsum...

\section{Some text}
    blah blah

\section{Structure}
%TOC of future document without page numbers, not referring to other current headings.

\section{Discussion}
Some Text

\end{document}

Should look like this:

Table of Contents
1  Introduction..................................1
2  Some text.....................................2
3  Structure.....................................4
4  Discussion....................................6


1 Introduction
Lorem ipsum...

2 Some text
blah blah

3 Structure
%TOC of future document without page numbers
  1  First Chapter
  2  Second Chapter
      2.1  A Subsection
      2.2  Another Subsection
          2.2.1 A Subsubsection
          2.2.1 Another Subsubsection
  3  Last Chapter
4 Discussion
Some Text

I was basically able to implement the proposed solution and have also tried to add a \subsubsection by myself but was not able to.

The other proposed solutions using enumitem has a different styling then my normal TOC. Would prefer to have the additional TOC in the same styling as my main TOC for the document.

Current Document without subsubsection and enumitem with wrong styling

Do you have any tips how to add a third layer to the KOMA-Script solution? Thanks a lot for your support!

2
  • 2
    This seems to be less about "having a TOC repeated", and more about "creating a fake TOC" (with subsubsections). Is that correct? Do you have the other document to use its toc file, or are you needing to create the fake toc from nothing?
    – Teepeemm
    Jan 30, 2021 at 19:09
  • Yes, it's like a "fake TOC". The future document is not existing yet. So it would be a fake toc from nothing. An Exposè is a planning document for a future document in this case my Bachelor Thesis.
    – KiQuz
    Jan 30, 2021 at 19:11

2 Answers 2

1

If you want to include subsubsection in the structure section of this solution, add subsubsection to the last argument of \DeclareTOCStyleEntries

latex
\BeforeStartingTOC[str]{%
  \DeclareTOCStyleEntries[
    linefill=\hfill,%
    pagenumberformat=\gobble%
  ]{tocline}{section,subsection,subsubsection}% <=== subsubsection added
}

and define the new counter strsubsubsection

\newcounter{strsubsubsection}
\counterwithin{strsubsubsection}{strsubsection}

Example:

\documentclass{scrartcl}
\DeclareNewTOC{str}
\BeforeStartingTOC[str]{%
  \DeclareTOCStyleEntries[
    linefill=\hfill,%
    pagenumberformat=\gobble%
  ]{tocline}{section,subsection,subsubsection}% <=== subsubsection added
}
\newcommand\gobble[1]{}

\newcounter{strsection}
\newcounter{strsubsection}
\counterwithin{strsubsection}{strsection}
\newcounter{strsubsubsection}% <=== added
\counterwithin{strsubsubsection}{strsubsection}% <=== added

\newcommand\addstr[2]{%
  \stepcounter{str#1}%
  \addxcontentsline{str}{#1}[\csname thestr#1\endcsname]{#2}%
}
\begin{document}
\tableofcontents

\section{Introduction}
    Lorem ipsum...

\section{Some text}
    blah blah

\section{Structure}
\listoftoc*{str}
\addstr{section}{First Section}
\addstr{section}{Second Section}
\addstr{subsection}{A Subsection}
\addstr{subsection}{Another Subsection}
\addstr{subsubsection}{A Subsubsection}% <=== added
\addstr{subsubsection}{Another Subsubsection}% <=== added
\addstr{section}{Last Section}

\section{Discussion}
\end{document}

enter image description here


But if you want to use a class with chapters (ie. scrreprt or scrbook) then you have to add the chapter level to the structure chapter:

\documentclass{scrreprt}
\DeclareNewTOC{str}
\BeforeStartingTOC[str]{%
  \DeclareTOCStyleEntries[
    linefill=\hfill,% no dots
    pagenumberformat=\gobble% no page number
  ]{tocline}{chapter,section,subsection}% <=== chapter added
}
\newcommand\gobble[1]{}

\newcounter{strchapter}% <=== added
\newcounter{strsection}
\counterwithin{strsection}{strchapter}% <=== changed
\newcounter{strsubsection}
\counterwithin{strsubsection}{strsection}

\newcommand\addstr[2]{%
  \stepcounter{str#1}%
  \addxcontentsline{str}{#1}[\csname thestr#1\endcsname]{#2}%
}
\begin{document}
\tableofcontents

\chapter{Introduction}
    Lorem ipsum...

\chapter{Some text}
    blah blah

\chapter{Structure}
\listoftoc*{str}
\addstr{chapter}{First Chapter}
\addstr{chapter}{Second Chapter}
\addstr{section}{A Section}
\addstr{section}{Another Section}
\addstr{subsection}{A Subsection}% <=== added
\addstr{subsection}{Another Subsection}% <=== added
\addstr{section}{Last Chapter}

\chapter{Last Chapter}
\end{document}
2
  • Thanks a lot! For my document it's somehow not working. It's not adding the subsubsections and just stays like shown in my initial screenshot. I have tried your solution in a new blank file. There everything seems fine. I am using a template from my university, so I guess there might be something interfering with it. Anyways, thanks a lot!
    – KiQuz
    Jan 31, 2021 at 2:26
  • Issue was caused by \setcounter{tocdepth}{2} somewhere else in the template. Changed it and now your solution is working fine.
    – KiQuz
    Jan 31, 2021 at 4:10
0

This is a general solution for having multiple ToCs, LoFs etc. It is not specific to the scrartcl class. Note it involves redefining a kernel macro.

% tocsprob.tex  SE 581163

\documentclass[]{scrartcl}

% Modify a kernel macro so that ToC, etc files only closed at the document end
\makeatletter
\renewcommand{\@starttoc}[1]{%
  \begingroup\makeatletter
    \@input{\jobname.#1}%
    \if@filesw
      \AtEndDocument{%
        \expandafter\newwrite\csname tf@#1\endcsname
        \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
      }%
    \fi
  \@nobreakfalse
  \endgroup}
\makeatother

\begin{document}
\tableofcontents

\section{Introduction}
    Lorem ipsum...

\section{Some text}
    blah blah
\subsection{A subsection}
\subsubsection{A subsubsection}
\paragraph{A paragraph} Text

\section{Structure}
Additional TOC defined here
% have ToC include \paragraph s
\addtocontents{toc}{\protect\setcounter{tocdepth}{4}} 
\tableofcontents

\end{document}

By default \subsubsection s are included in the ToC. I have shown how to include \paragraph s in the second ToC in case you ever need that.

(The memoir class allows multiple ToC, etc., by default.)

enter image description here

3
  • Thanks a lot for your answer. If i understand it correctly, the second TOC is also referring to the existing headings of the document. Maybe i havent explained it well enough, sorry. The second TOC i need, will be the TOC of a future document, so must not contain existing headings, but will be a new one.
    – KiQuz
    Jan 30, 2021 at 18:54
  • @KiQuz So that is a completely different question. I answered your oroginal question, basically "How can I have multiple ToCs in my document?" to "How can I have the current ToC in my document plus a ToC from a document yet to be processed?" Jan 31, 2021 at 18:14
  • Yes, sorry. English is not my mother tongue, but i tried my best to explain it as detailed as possible. I will clean up my question later on to have a better documentation for everyone.
    – KiQuz
    Jan 31, 2021 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .