1

I have to write an essay about another text. Therefore, I have to attach an additional table of contents, which does not actually show my document's structure, but lists sections that are not included in my document.

To clarify: There should be a normal TOC that lists my sections plus another TOC placed anywhere in my own document - not necessarily in the appendix or so.

To make things a little bit more difficult, the "second" TOC should not contain page numbers.

\documentclass[]{scrartcl}

\begin{document}
\tableofcontents

\section{Introduction}
    Lorem ipsum...

\section{Some text}
    blah blah

\section{Structure}
%Additional TOC defined here

\end{document}

It should look like this:

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


1 Introduction
Lorem ipsum...

2 Some text
blah blah

3 Structure
  1  First Chapter
  2  Second Chapter
      2.1  A Subsection
      2.2  Another Subsection
  3  Last Chapter

Thanks for sharing your ideas.

1

If the additional "TOC" should use the same settings for the section and subsection entries:

\documentclass[toc=sectionentrywithdots]{scrartcl}[2018/12/30]% needs version 3.26a
\DeclareNewTOC{str}
\BeforeStartingTOC[str]{%
  \DeclareTOCStyleEntries[
    linefill=\hfill,% no dots
    pagenumberformat=\gobble% no page number
  ]{tocline}{section,subsection}%
}
\newcommand\gobble[1]{}

\newcounter{strsection}
\newcounter{strsubsection}
\counterwithin{strsubsection}{strsection}

\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 Chapter}
\addstr{section}{Second Chapter}
\addstr{subsection}{A Subsection}
\addstr{subsection}{Another Subsection}
\addstr{section}{Last Chapter}

\end{document}

enter image description here


Because of a comment below: Overleaf seems to use an older TeX-Distribution, so \counterwithin needs package chnngcntr. The KOMA-Script Version there is outdated, too: a new project uses version KOMA-Script version 3.23, current version on CTAN is 3.26b. So you can not use \DeclareTOCStyleEntries. You have to replace it by two \DeclareTOCStyleEntry commands.

\documentclass[toc=sectionentrywithdots]{scrartcl}[2017/04/13]% tested for version 3.23
\usepackage{chngcntr}% <- needed for older TeX Distributions

\DeclareNewTOC{str}
\BeforeStartingTOC[str]{%
  \DeclareTOCStyleEntry[
    linefill=\hfill,% no dots
    pagenumberformat=\gobble% no page number
  ]{tocline}{section}%
  \DeclareTOCStyleEntry[
    linefill=\hfill,% no dots
    pagenumberformat=\gobble% no page number
  ]{tocline}{subsection}%
}
\newcommand\gobble[1]{}

\newcounter{strsection}
\newcounter{strsubsection}
\counterwithin{strsubsection}{strsection}

\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 Chapter}
\addstr{section}{Second Chapter}
\addstr{subsection}{A Subsection}
\addstr{subsection}{Another Subsection}
\addstr{section}{Last Chapter}

\end{document}

The result is the same as above.

  • This is exactly what I searched for. But when pasting your code to Overleaf, it throws me four errors. After adding \usepackage{chngcntr}, there are two left: Undefined control sequence. l.36 \listoftoc*{str} and LaTeX Error: Something's wrong--perhaps a missing \item. l.1 ... {section}{\numberline {1}First Chapter}{1}. After commenting out the DeclareNewTOC block, all errors are gone, but the additional TOC has page numbers. – ckuenzle Jun 9 at 7:38
  • Overleaf uses an older TeX Distribution and an outdated KOMA-Script version. You have to replace \DeclareTOCStyleEntries by two \DeclareTOCStyleEntry commands: one for strsection and one for strsubsection. See my updated answer. – esdd Jun 9 at 15:54
1

I'd just use lists.

\documentclass{article}

\usepackage{enumitem}

\begin{document}

{
    \setlist[enumerate]{label*=.\arabic*}
    \setlist[enumerate, 1]{label=\arabic*}
    \begin{enumerate}
        \item First Chapter
        \item Second Chapter
        \begin{enumerate}
            \item A Section
            \item Another Section
            \begin{enumerate}
                \item A Subsection
                \item One More Subsection
            \end{enumerate}
        \end{enumerate}
        \item Last Chapter
    \end{enumerate}
}

\end{document}

MWE output

You can easily configure the appearance of the lists using enumitem and keep the design local by enclosing everything in a group.

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.