7

I would like to combine both section numbering and bullets in the table of contents of a document of article class just to avoid so much long section number (for example 1.2.1.1.1).

So, I would like to have something like this:

1. First section
   1.1 First subsection
   1.2 Second subsection
           1.2.1 First subsubsection
             · First paragraph
             · Second paragraph
               - First subparagraph
   1.3 Third subsection
2. Second section

How can I modify the table of contents to put those bullets instead of numbers?

  • Are your paragraphs and subparagraphs numbered in the main body of the text, or are they marked with bullets and dashes, resp.? Separately, do ask yourself if you need to list the paragraph and subparagraph headers in the ToC. – Mico Apr 9 '14 at 8:32
  • Yes, I completely need the paragraph and subparagraph headers in the ToC for this article. In the main body of the text I use numbered paragraphs and unnumbered subparagraphs. – Urko Apr 9 '14 at 8:35
5

The entries for \paragraph and \subparagraph in the table of contents are set by the macros: \l@paragraph and \l@subparagraph. Usually the class contains their definition. Example for class article:

\newcommand*\l@subsubsection{\@dottedtocline{3}{3.8em}{3.2em}}
\newcommand*\l@paragraph{\@dottedtocline{4}{7.0em}{4.1em}}
\newcommand*\l@subparagraph{\@dottedtocline{5}{10em}{5em}}

The arguments for \@dottedtocline are:

  • Section level (e.g., 4 for \paragraph).
  • Indent to the left margin.
  • Space for the numbering for macro \numberline.
  • Section title (inherited from \contentsline). If a number is given, it starts with \numberline{...} right before the section title in the same argument.
  • ...

The following example redefines the macros \l@paragraph and \l@subparagraph:

  • Length parameters of \@dottedtocline are updated to respect the smaller numbering using symbols only.
  • The symbol is added as "number" with \numberline for formatting reasons.
  • The original number is gobbled if present.
\documentclass{article}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{5}

\makeatletter
\renewcommand*{\l@paragraph}[1]{%
  \@dottedtocline{4}{7.0em}{1em}{%
    \numberline{\textbullet}%
    % \numberline{$\cdot$}%
    \gobble@numberline
    #1%
  }%
}
\renewcommand*{\l@subparagraph}[1]{%
  \@dottedtocline{5}{8em}{1em}{%
    \numberline{\textendash}%
    \gobble@numberline
    #1%
  }%
}
\newcommand*{\gobble@numberline}{%
  \@ifnextchar\numberline{\@gobbletwo}{}%
}
\makeatother

\newcommand*{\lipsum}{%
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit.%
}

\begin{document}
  \tableofcontents

  \newpage
  \section{First section}
  \subsection{First subsection}
  \subsection{Second subsection}
  \subsubsection{First subsubsection}
  \paragraph{First paragraph}
  \paragraph{Second paragraph. \lipsum}
  \subparagraph{First subparagraph}
  \subparagraph{Second subparagraph. \lipsum}
  \subsection{Third subsection}
  \section{Second section}
\end{document}

Result

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.