Single Spacing LaTeX TOC: Simple Fix

  • LaTeX
  • Thread starter Pengwuino
  • Start date
  • Tags
    Latex
In summary, you need to write a \tableofcontents macro that uses this given table of contents command.
  • #1
Pengwuino
Gold Member
5,124
20
I'm running in the report document class and I was wondering how does one make the table of contents single spaced? Or possibly even 1 1/2 spaced. I tried some suggestions involving the tocloft package and everything pretty much went to hell. Due to some annoying issues with how the theses need to be done (I hate my university), the table of contents is created by

\chapter*{Chapter name}
\addcontents{toc}{chapter}{Chapter name}

Does anyone know a simple way to single space or 1 1/2 space the entries in the TOC?

Do I need to provide anymore info?

The style file I use has something about the table of contents as

Code:
 \def\tableofcontents{\@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn
 \fi \chapter*{TABLE OF CONTENTS\@mkboth{CONTENTS}{CONTENTS}}
 \@starttoc{toc}\if@restonecol\twocolumn\fi}

but I'm a bit clueless as to what's going on there :)
 
Physics news on Phys.org
  • #2
\setlength in the preamble with tocloft is the usual way to customize TOC without editing the style.

The [itex]\LeTeX[/itex] default is single space though - oh but you have a TOC with only chapter headings?

Code:
\documentclass{book}
\usepackage{tocloft}

\setlength\cftparskip{-2pt}
\setlength\cftbeforechapskip{0pt}

\begin{document}
\tableofcontents
\clearpage

\chapter{Test chapter one}
\chapter{Test chapter two}

\end{document}
 
  • #3
I have chapters and sections :) The thesis is mainly double spaced so I declared double spacing at the very beginning of everything.

I really want to avoid using tocloft because the style file I'm using does it's own stuff to the table of contents. Tocloft makes my headings for the TOC, LOF, and LOT go a bit crazy.
 
  • #4
Pengwuino said:
The style file I use has something about the table of contents as

Code:
\def\tableofcontents{\@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn
 \fi \chapter*{TABLE OF CONTENTS\@mkboth{CONTENTS}{CONTENTS}}
 \@starttoc{toc}\if@restonecol\twocolumn\fi}

but I'm a bit clueless as to what's going on there :)
It's forcing the table of contents to be single column even if the document proper is two column.

So write your own \tableofcontents macro that uses this given table of contents command. NOTE WELL: THIS IS NOT TESTED:
Code:
\let\@saved@tableofcontents\tableofcontents
\def\tableofcontents{\begingroup\singlespace\@saved@tableofcontents\endgroup}
 
  • #5
I assume I put that after the first part that I posted? I'm pretty clueless about latex :P

I put it after and I noticed the TOC shifted but was still double spaced.

Could it be because the TOC isn't being generated automatically as expected and instead is being compiled with \addcontents{toc}{chapter}{blahblahblah}?
 
  • #6
Oh now I get you - you want to start out single space for the toc and switch to double-space for the body. That would be quite unusual as a standard, which is probably why the style doesn't support it.

How about set the document to single-space and :

\usepackage{setspace}

Then switch between different spacing options with:

\doublespacing
\singlespacing
\onehalfspacing

For other sizes use the \setstretch command like this:

\setstretch{1.8}

Double-spacing is usually only used in drafts - which is often what is requested for marking. The actual paper would use a different format.
 
  • #7
Thanks for the help guys. I just realized some code after that going as

Code:
 \def\l@chapter{\par
                \baselineskip 0.15in  % added for smaller spacing
                \@dottedtocline{1}{0.0em}{2.6em}}
 \def\l@section{\baselineskip 0..15in  % added for smaller spacing
                \@dottedtocline{1}{2.6em}{2.3em}}
 \def\l@subsection{\baselineskip 0..15in  % added for smaller spacing
                   \@dottedtocline{2}{4.9em}{3.2em}}
 \def\l@subsubsection{\baselineskip 0.20in  % added for smaller spacing
                     \@dottedtocline{3}{8.1em}{4.1em}}
 \def\l@paragraph{\baselineskip 0.20in  % added for smaller spacing
                 \@dottedtocline{4}{12.2em}{5em}}
 \def\l@subparagraph{\baselineskip 0.20in  % added for smaller spacing
                    \@dottedtocline{5}{17.2em}{6em}}

was responsible for changing the spacing upon adding things to the TOC. I didn't really see anything that made me think it was doing anything to the TOC, but apparently it is :)
 
  • #8
Pengwuino said:
I just realized some code after that going as...

Yup, that's the right place to be. If you do
Code:
\addcontents{toc}{foo}{...}
the TOC entry is printed by the command
Code:
\l@foo

There's nothing special about using format identifiers like "chapter", "section" etc, except those are what the \chapter{...} and \section{...} commands generate for free. If you want to do something really fancy (like including short chapter summaries in the contents or whatever) you might want to define some additional formats.

The spacing of the TOC is (almost) completely independent of the spacing of the rest of the document, so \singlespace etc won't change anything.

I didn't really see anything that made me think it was doing anything to the TOC
Look at your .toc file, then read the code of \contentsline (assuming your packages haven't renamed it as something else). \contentsline is what makes the parameter "foo" execute the command \l@foo.
 
Last edited:

1. What is single spacing in LaTeX?

Single spacing in LaTeX refers to the amount of space between lines of text in a document. In a single-spaced document, each line of text is separated by a fixed amount of space, typically equivalent to the size of one line of text. This is in contrast to double spacing, where each line is separated by two lines of space.

2. How do I change the spacing in my LaTeX table of contents?

To change the spacing in your LaTeX table of contents, you can use the "setspace" package. Simply include the command "\usepackage{setspace}" in your document preamble, and then use the "\setstretch" command to specify the desired spacing. For example, "\setstretch{1.5}" will result in 1.5 line spacing, while "\setstretch{2}" will result in double spacing.

3. Can I change the spacing for just the table of contents in my LaTeX document?

Yes, you can change the spacing for just the table of contents in your LaTeX document by using the "\singlespacing", "\onehalfspacing", or "\doublespacing" commands within the "\tableofcontents" environment. These commands will only affect the spacing within the table of contents, and the rest of your document will remain at the default spacing.

4. Why is my LaTeX table of contents double spaced by default?

In LaTeX, the default spacing for the table of contents is double spaced. This is because it is typically used for longer documents, such as books or theses, where double spacing is the standard for readability. However, you can easily change the spacing to single or one and a half by following the steps outlined in the previous questions.

5. Is there a way to customize the spacing in my LaTeX table of contents?

Yes, there are several ways to customize the spacing in your LaTeX table of contents. In addition to using the "\setstretch" command as mentioned earlier, you can also use the "\linespread" command to specify a specific spacing factor. Additionally, you can use the "titletoc" package to adjust the spacing of specific sections within the table of contents, such as chapter titles or page numbers.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
11K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top