[Tex/LaTex] TOC line indent and break problem

indentationline-breakingtable of contents

I have long chapter and section titles in my document, so titles in the table of contents do not fit into one line. I have two problems regarding with this:

  1. When the second line starts, i need to indent it to the right a bit, but i do not know how.
  2. When a chapter title is too long to fit in one line, the line continues till the margin of the page numbers. I need this line to cut before the page number box, leaving this space empty and continue with the second line.

Here is an example:

\documentclass[12pt]{report} 
\usepackage{styles/fbe_tez}
\begin{document} 
  \tableofcontents
  \chapter{FORMAT OF DISKETTES/CD CONTAINING COMPUTER SOFTWARE} 
    Some text here 
  \section{Table of Contents, List of Figures, List of Tables and List of Symbols/Abbreviations} 
  Some more text 
\end{document}

The style package is provided to me and here is the part relevant to the toc.

%
% Table of Contents
%
\renewcommand\contentsname{TABLE OF CONTENTS}
\renewcommand\tableofcontents{% \ev is used for temporary storage of \parskip
\newlength\ev
\setlength{\ev}{\parskip}
\parskip0pt
% A line as 'TABLE OF CONTENTS' must not appear in the
% Table of Contents. Hence we reproduce the \chapter* here except that
% no entry is put into the toc file.
     \clearpage  \global\@topnum\z@
     \@afterindenttrue
     \begin{center}
      { \normalfont
       \interlinepenalty\@M
       \large \bfseries  \contentsname\par\nobreak
       \vskip21pt \vskip0.8\baselineskip
      }\end{center}
     \@afterheading
     \@starttoc{toc}%
\parskip\ev}
%
% FBE style TOC does not have bold lines.
\renewcommand\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\leaders\hbox{$\m@th \mkern \@dotsep mu.\mkern \@dotsep
       mu$}\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
%
% The spacing of the TOC lines has been redefined.
\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.em}}
\renewcommand*\l@subsection{\@dottedtocline{2}{3.8em}{2.9em}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{7em}{3.8em}}
\renewcommand*\l@paragraph{\@dottedtocline{4}{11.1em}{4.7em}}
\renewcommand*\l@subparagraph{\@dottedtocline{5}{16.1em}{5.7em}}

Best Answer

You could use the tocloft package to customize the table of contents. It provides commands to modify indentation and page number width. Have a look at the documentation (texdoc tocloft or follow the link to CTAN), search for the macros \cftXindent and \cftXnumwidth for instance.

Without tocloft it may be a bit harder, for instance by adjusting \@pnumwidth like mentioned in The format of the Table of Contents in the UK TeX FAQ.

Related Question