13

Is this wrong?

Table of Contents

It seems the ToC does dotfilling only for sections and not subsections. Why is this happening and how can I fix it?

I'm using \tableofcontents and nothing else to generate this ToC, the document class is article.

Edit: Yes; I want to fill the space in the sections with dots, from the end of the section title to the beginning of the number, just like how it fills with dots the subsection 5.1

MWE below:

   \documentclass[a4paper,spanish]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage[spanish]{babel}
\usepackage{graphicx} 
\usepackage{wrapfig}
\usepackage{setspace}
\usepackage[right]{eurosym}
\usepackage{rotating}
\usepackage{ccicons}
\usepackage{multirow}
\usepackage{tabu}
\usepackage{amsmath,amssymb,amsthm,amscd}
\usepackage{amsmath}
\graphicspath{{./Imagenes/}} %Lugar en el que se guardarán las imágenes
\itemsep 1ex
\newcommand{\RNum}[1]{\uppercase\expandafter{\romannumeral #1\relax}}
\begin{document}

\tableofcontents % Índice

\newpage % Salto de página

\section{Los tres tipos generales de conocimiento} % Sección superior
bar
\section{Superioridad del saber-que}
foo
\section{Lo inefable}
barfoo
\section{Las condiciones de la verdad}
foobar
\section{Las fuentes del conocimiento}
bar
\subsection{La experiencia sensorial}
foo
\end{document}
1
  • Do you really mean that you have dots for section? \part and section are the levels without dots in the table of contents. Commented Mar 9, 2013 at 20:04

2 Answers 2

4

If you don't want to look for the right lengths to give as parameters to tocloft or titletoc commands, you can also patch the \l@section command to use the same leaders as the other commands instead of blank space:

\documentclass[a4paper]{article}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@section}
  {\hfil}
  {\leaders\hbox{\normalfont$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}\hfill}
  {}{}
\makeatother

\begin{document}

\tableofcontents % Índice

...
\end{document}

enter image description here

1
  • Thank you for your detailed explanation and illustrated example on this! Very much appreciating the quick response aswell! Cheers :) This is exactly what I was looking for!! Commented Mar 10, 2013 at 0:16
18

In article.cls the default behaviour for section entries in the ToC is not to use the dotted leaders; if you want to have these, you can use the tocloft package and redefine \cftsecleader to have the dots:

\documentclass{article}
\usepackage{tocloft}

\renewcommand\cftsecleader{\cftdotfill{\cftdotsep}}

\begin{document}

\tableofcontents
\section{Test Section}
\subsection{Test Subsection}

\end{document}

enter image description here

Another option would be to use the titletoc package and its \dottedcontents command:

\documentclass{article}
\usepackage{titletoc}

\dottedcontents{section}[1.5em]{\bfseries}{1.3em}{.6em}

\begin{document}

\tableofcontents
\section{Test Section}
\subsection{Test Subsection}

\end{document}

enter image description here

Yet another option, not requiring additional packages, would be to redefine the internal command \l@section (in charge of typesetting section entries in the ToC) to use \@dottedtocline:

\documentclass{article}

\makeatletter
\renewcommand*\l@section{\@dottedtocline{1}{0em}{1.5em}}
\makeatother

\begin{document}

\tableofcontents
\section{Test Section}
\subsection{Test Subsection}

\end{document}

enter image description here

2
  • 1
    And with tocstyle it is also possible.
    – Speravir
    Commented Mar 9, 2013 at 23:07
  • Thanks for your accurate and detailed listing of the several methods available, I'm just learning LaTeX and I'm already loving it. Your answer is highly appreciated :) Commented Mar 10, 2013 at 0:19

You must log in to answer this question.

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