TeXnik - Tips TeX and LaTeX


Welcome to the TeXnik website (under construction)

TOC-faq
TUG logo

Main page

Index
UK FAQ
Documentation
Software
CTAN
Search CTAN:

Statistics

Google c.t.t.

Google d.c.t.t.

 


 


Bibliography in TOC |  chapter*/section* into TOC  |  Continuing TOC (more than one page) |  Dotted lines for chapter |  Format of TOC |  Headerline |  Labelwidth |  Labelwidth with tocloft |  pagenumber |  TOC-Style |  TOC-Style with tocloft package |  Unnumbered Chapters/Sections into TOC |  Vertical Space  | 


Vertical Space
If you do not like the extra vertical space in toc, lof, lot, ... when a new chapter begins, then write just before you want to place the different lists:
\begingroup
\renewcommand*{\addvspace}[1]{}
\listoffigures
\listoftables
...
\endgroup
This decreases only the addtional space to the default one. To get rid of any vertical space between chapter entries write into the preamble:
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
%    \vskip 1.0em \@plus\p@% <--- the vertical space
    \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}
Changing the vertical space between the title line and the first item is possible for the KOMA classes with

For all other classes write into your doc, where the toc should appear:
\begingroup
\makeatletter
\renewcommand*{\addvspace}[1]{}
\def\@makeschapterhead#1{%
%  \vspace*{50\p@}% <---  space above TOC header
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries  #1\par\nobreak
%    \vskip 40\p@% <---- space below TOC header
  }}
\makeatother
\tableofcontents
\endgroup
The above example decreases all vertical space to zero!


Dotted lines between Title and Pagenumber

By default the TOC has only dotted lines between title and pagenumber for section and lower.

CHAPTER TITLE                                                       2
   Section Title ...................................................2
If you want to have this for chapters or part too,
CHAPTER TITLE ......................................................2
   Section Title ...................................................2
write in LateX preamble (only for classes with chapters):
\makeatletter
\renewcommand*\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\ 
       \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfil\nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
\makeatother
For classes without a chapter write
\makeatletter
\renewcommand\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode {\bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1}\nobreak\ 
      \leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}
     \hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
\makeatother


pagenumber at the TOC-pages

with \thispagestyle{empty} you can suppress the pagenumbering for a single page. If you want use this for the TOC-pages it doesn't work if your TOC is longer than one page. Than you'll get a numbered page with the beginning of the second TOC-page. To prevend this write just at the position in your text, where the TOC shall be:

\tableofcontents
\addtocontents{toc}{\protect\thispagestyle{empty}}
If you have installed the fancyhdr package, look at this page for redefining the plain-style for headers and footers.

If you have a TOC of several pages, than try this in the preamble

\makeatletter
\let\myTOC\tableofcontents
\renewcommand{\tableofcontents}{%
  \begingroup
  \let\ps@plain\ps@empty
  \pagestyle{empty}
  \myTOC
  \clearpage
  \endgroup%
}
\makeatother
Insert the TOC in your doc as usual. You can delete the \clearpage statement if you do not need a new page.

Bibliography in TOC

Just before your command to insert your Bibfile in the document write

\addcontentsline{toc}{chapter}{Bibliography}
% \addcontentsline{toc}{section}{Bibliography}% alternative for article class
for book style put the cursor before this command and than layout->paragraph->pagebreak before! For twocolumnmode you can also try to write these latex commands just before you insert the bib:
\let\myCDP\cleardoublepage
\renewcommand\cleardoublepage{%
   \myCDP
   \addcontentsline{toc}{chapter}{Bibliography}
}
< insert here the bibfile as usual >
for chapter you can choose any other level like part, section, subsection ,... in this case the name Bibliography appear in the TOC just like a chapter, means bold characters.
Bibliography is the name which appears in the TOC, you can change it to your own language, like Literaturverzeichnis in german
with package hyperref choose \phantomsection

with \addcontensline a pagenumber is printed in the TOC. with

\addtocontents{toc}{Bibliography}
you'll get only the word Bibliography in the TOC (with standard-font).


Labelwidth in TOC without tocloft
If you don't want to use the package tocloft look in your desired classfile for lines like these one:

\makeatletter
\newcommand*\l@section{\@dottedtocline{1}{1.5em}{2.3em}}
\newcommand*\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}
\newcommand*\l@subsubsection{\@dottedtocline{3}{7.0em}{4.1em}}
\newcommand*\l@paragraph{\@dottedtocline{4}{10em}{5em}}
\newcommand*\l@subparagraph{\@dottedtocline{5}{12em}{6em}}

\newcommand*\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}
\makeatother
and the same for list of tables (lot) with
\makeatletter
\let\l@table\l@figure
\makeatother
the first value is the left indent and the second one the labelwidth. you change them just you like it. for example try a
\renewcommand{\l@section}{\@dottedtocline{1}{1.5em}{6em}}
in LaTeX-preamble for sections, which should give enough space ... ;-)

For more Information have a look at the TeX-faq

If you want to change the labelwidth only for parts of the TOC, you have to do it on this way (for example: koma-script):

\makeatletter
\newlength{\myLabelWidth}
\setlength{\myLabelWidth}{1.5em}% <--- the standard value
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{\myLabelWidth}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \sectfont
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
\makeatother
For changing the labelwidth for the appendix write in the text just behind the command \appendix or \begin{appendix}

\addtocontents{toc}{\addtolength{\myLabelWidth}{6em}}


TOC Style

Changing the style with package tocloft is easier!

local time: Sat Dec 7 19:37:47 CET 2019 ; file is: 161.962222222222 days old
contact webmaster _at_ TeXnik.de