1

I am putting together a report as part of a group project for part of physics degree, and I have been having fun trying to format the table of contents correctly. Here is a MWE:

 \documentclass[twoside]{article} \usepackage[a4paper,pdftex,left=1.7cm,right=1.7cm,top=2cm,bottom=2.5cm]{geometry} \usepackage{blindtext} \usepackage[english]{babel} \renewcommand*\thesection{\arabic{section}.0} \renewcommand*\thesubsection{\arabic{section}.\arabic{subsection}} \begin{document} \tableofcontents \addtocontents{toc}{~\hfill\textbf{Page}\par} \newpage \begin{abstract} \blindtext \end{abstract} \section{A section} \blindtext \section{Another section} \blindtext \subsection{A subsection} \blindtext \subsection{Yet another subsection} \blindtext \subsubsection{Oh, exciting, a sub sub section!} \blindtext \section{Another boring old section} \blindtext \end{document} 

Which gives something like this as the output:

Not bad, except for the spacing between the sections and their respective numbers is far too small. I tried to fix it by including this in the preamble:

 \makeatletter \renewcommand{\l@section}{\@dottedtocline{1}{1.5em}{3em}} \renewcommand{\l@subsection}{\@dottedtocline{2}{3.0em}{3.5em}} \renewcommand{\l@subsubsection}{\@dottedtocline{3}{4.5em}{4.2em}} \makeatother 

giving this:

Although it allows me to adjust the spacing to my liking (not adjusted correctly in the picture, just an example), I seem to have lost the bold font and gained some dots for my sections which were previously absent. I have also lost the nice spacing between sections. I tried getting the bold font back with

 \renewcommand\cftsecfont{\bfseries} 

but it didn't seem to have any effect. Any advice on how to better format my ToC would be appreciated. I don't have to comply with any specific layout of formatting specified by the university, but I do want it to look clear and professional. The first example was perfect except for the section numbers being stuck right next to the sections, although it was fine for the subsections.

3
  • Welcome to TeX.SX! Why ` \renewcommand*\thesection{\arabic{section}.0}`? Commented Feb 16, 2015 at 12:38
  • Thanks for the welcome - see my response to Christian Hupfer for the reasoning behind the additional '0.1'. Although removing that temporarily fixes it, the spacing still becomes an issue with the number of sections enters double digits. Commented Feb 16, 2015 at 14:15
  • potential duplicate: How to modify the indentation before sectioning titles in the table of contents? Commented Feb 16, 2015 at 14:30

1 Answer 1

1

The width used for the section numbers in a Toc (article class) can be set by readjusting

\cftsecnumwidth to an appropiate value (30ptin my example).

The package tocloft is needed for this.

I don't understand the purpose of

\renewcommand*\thesection{\arabic{section}.0} however.

 \documentclass[twoside]{article} \usepackage[a4paper,pdftex,left=1.7cm,right=1.7cm,top=2cm,bottom=2.5cm]{geometry} \usepackage{blindtext} \usepackage[english]{babel} \usepackage{tocloft} \renewcommand*\thesection{\arabic{section}.0} \renewcommand*\thesubsection{\arabic{section}.\arabic{subsection}} \renewcommand{\cftsecnumwidth}{30pt} \setcounter{tocdepth}{3} \setcounter{secnumdepth}{4} \begin{document} \tableofcontents \addtocontents{toc}{~\hfill\textbf{Page}\par} \newpage \begin{abstract} \blindtext \end{abstract} \section{A section} \blindtext \section{Another section} \blindtext \subsection{A subsection} \blindtext \subsection{Yet another subsection} \blindtext \subsubsection{Oh, exciting, a sub sub section!} \blindtext \section{Another boring old section} \blindtext \end{document} 

enter image description here

4
  • This is definitely a duplicate ;-) Commented Feb 16, 2015 at 13:25
  • @Johannes_B: Yes, most likely Commented Feb 16, 2015 at 13:25
  • Brilliant, thank you. I am sorry if this is a duplicate, but none of the previous answers I could find seemed to work in the article class or without using tocloft or similar. The extra '.0' for sections was how the lab demonstrator told me to format my lab reports last year, however this came from the same demonstrator who told me sunlight took around 50 seconds to reach the earth and that magnetic perpetual motion machines were theoretically possible, so I am quite willing to accept that his notions of report formatting were also incorrect... Thanks again for the help. Commented Feb 16, 2015 at 14:11
  • @George: The manual of tocloft reveals a lot of deals (although a little bit hard to read ;-)) The .0 is indeed... eh, weird ;-) Commented Feb 16, 2015 at 14:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.