1

I know that the indenting size of chapter, section and subsection can be changed in tocloft package using \cftsetindents. I am using a Latex template and I shouldn't use tocloft or any other TOC packages. So my question is how can I control those indents in the standard TOC? it's okay if I need to modify the cls files, etc but I don't know what are the settings to be changed.

\documentclass[singlespace,tocchapterhead,a4paper,openright,twoside]{MyThesisEnglish}
\usepackage{paralist}
\usepackage{natbib}
\usepackage[figuresright]{rotating}
\usepackage{lscape}
\usepackage[caption=false]{subfig}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{calc}
\usepackage{mathrsfs}
\usepackage{stmaryrd}
\usepackage{eucal}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{epsfig}
\usepackage{setspace}
\usepackage{color}
\usepackage{epstopdf}
\usepackage{dsfont}
\usepackage{algorithmic}
\usepackage{textcomp}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{url}
\usepackage{tipa}
\usepackage{array}
\citestyle{unsrt}
\usepackage[top=25mm, bottom=25mm, left=40mm, right=25mm]{geometry}


\begin{document}
\pagenumbering{roman}


\include{Title}


\addcontentsline{toc}{chapter}{\textbf{DEDICATIONS}}
\include{Dedication}


\addcontentsline{toc}{chapter}{\textbf{ABSTRACT}}
\include{Abstract}


\addcontentsline{toc}{chapter}{\textbf{\textit{ABSTRACT2}}}
\include{ABSTRACT2}


\addcontentsline{toc}{chapter}{\textbf{ACKNOWLEDGEMENTS}}
\include{Acknow}


\addcontentsline{toc}{chapter}{\textbf{APPROVAL}}
\include{Approval}


\addcontentsline{toc}{chapter}{\textbf{DECLARATION}}
\include{Declaration}


\makeatletter
\renewcommand{\@dotsep}{10000}
\makeatother


\tableofcontents
\listoftables
\listoffigures
\newpage
\addcontentsline{toc}{chapter}{\textbf{LIST OF ABBREVIATIONS}}
\include{abbrev}


\mainmatter
\singlespace


\addtocontents{toc}{\addvspace{.5cm}}
\include{Chapter1}
\addtocontents{toc}{\addvspace{.5cm}}
\include{Chapter2}
\addtocontents{toc}{\addvspace{.5cm}}
\include{Chapter3}
\addtocontents{toc}{\addvspace{.5cm}}
\include{Chapter4}
\addtocontents{toc}{\addvspace{.5cm}}
\include{Chapter5}
\addtocontents{toc}{\addvspace{.5cm}}
\include{Chapter6}


\addcontentsline{toc}{chapter}{\textbf{REFERENCES/Bibliography}}
\begin{singlespace}
\bibliography{bibfile}
\bibliographystyle{ai}
\end{singlespace}

\newpage
\addcontentsline{toc}{chapter}{\textbf{APPENDICES}}
\appendix
\include{AppendixA}
\include{AppendixB}


\addcontentsline{toc}{chapter}{\textbf{BIODATA OF STUDENT}}
\include{biodata}                                                %
\addcontentsline{toc}{chapter}{\textbf{LIST OF PUBLICATIONS}}
\include{listofpublications}                                    %
\end{document}

Update: I increased the indention for chapter titles using \setlength\@tempdima{5.5em} but still couldn't find the way to increase the indention of sections and subsections. https://imgur.com/a/3lUcG

\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
\setcounter{secnumdepth}{3}%
\setcounter{tocdepth}{2} %   
    \addpenalty{-\@highpenalty}%
    \vskip .1cm \@plus \p@ %{the v-distance between the headings in the contents}
    \setlength\@tempdima{5.5em}% %{the distance between the number of the chapter and its title}
    \begingroup
           \parindent\z@ \rightskip \@pnumwidth
            \parfillskip -\@pnumwidth
      \leavevmode
      \advance \leftskip \@tempdima 
      \hskip  -\leftskip 
      \etchapterheadstyle{#1}\nobreak
% CCW: The following 3 lines add dots to the chapter TOC listings
      \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfill
      \hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi} 
7
  • 1
    Welcome to TeX SX! Unrelated: epsfig is totally obsolete (for more than twenty years) and should be replaced with \includegraphics. Is there any reason not to use a toc package? You load geometry, which certainly modifies the general layout. – Bernard Jan 9 '18 at 19:59
  • You're loading epstopdf twice, by the way – user31729 Jan 9 '18 at 19:59
  • @Bernard Thanks for your reminder about theepsfig package. Other toc packages change the appearance of the table of content and I don't have time to change them back to the original design. I just need to increase the indents. – R. Toward Jan 9 '18 at 20:09
  • 1
    The chapter (for example) TOC entry is formatted by \l@chapter, so search MyThesisEnglish.cls for \l@chapter an modify accordingly. Often these use \@dottedtocline where the indentation is the second argument. – John Kormylo Jan 9 '18 at 21:35
  • And you probably don't need to load epstopdf at all unless you're using a really old version of TeX. – cfr Jan 10 '18 at 0:47
2

The ToC entries for \chapters, \sections and \subsections are handled by \l@chapter, \l@section and \l@subsection, respectively. Here are the definitions of each (from report.cls):

\newcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
\newcommand*\l@section{\@dottedtocline{1}{1.5em}{2.3em}}
\newcommand*\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}

Within \l@chapter, the length \@tempdima specifies the box width that holds the chapter number. The default definition, as you can see above, is 1.5em. You can change this using the following

\usepackage{etoolbox}
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@chapter}{1.5em}{5.5em}{}{}
\makeatother

to increase the box width to 5.5em, say.

Note how \l@section's definition also uses 1.5em as the first length parameter, followed by 2.3em. The first length is the indentation, while the second length is the width of the box containing the section number. The first length in \l@subsection is 3.8em (or 1.5em + 2.3em) and puts its number in a box of width 3.2em. So it seems the indentation of the sub-level is the sum of the indentation of its parent level and the parent's box width. With this is mind, \l@subsubsection should have an indentation of 7em (3.8em + 3.2em):

\newcommand*\l@subsubsection{\@dottedtocline{3}{7.0em}{4.1em}}

Look at that!

You can change the \section and \subsection indentation to now coincide with your 5.5em \l@chapter number-box width using

\makeatletter
\patchcmd{\l@section}{5.5em}{2.3em}{}{}% Since \l@chapter uses 5.5em for \@tempdima
\patchcmd{\l@subsection}{7.8em}{3.2em}{}{}% Since \l@section uses 5.5em + 2.3em
\makeatletter
4
  • Thanks, this works well. \patchcmd{\l@chapter}{1.5em}{5.5em}{}{} \patchcmd{\l@section}{1.5em}{5.5em}{}{} \patchcmd{\l@subsection}{3.8em}{7.8em}{}{} The only problem is that the chapter titles are long and when line breaks there is double-space gap between the first line and the second line of the chapter title. How to remove the extra space? – R. Toward Jan 10 '18 at 9:53
  • More info: imgur.com/a/Ex901 – R. Toward Jan 10 '18 at 10:06
  • @R.Toward: That may be related to your use of \addtocontents{toc}{\addvspace{.5cm}} before including every chapter. Perhaps try \addtocontents{toc}{\par\addvspace{.5cm}} (can't test it since I don't have your \documentclass or chapters). – Werner Jan 10 '18 at 16:20
  • Adding \par or removing the {\addvspace{.5cm}} doesn't affect the result. I have uploaded the cls file here. textuploader.com/dmdg6 – R. Toward Jan 10 '18 at 16:55

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.