[Tex/LaTex] What’s wrong with the table of contents

table of contentstocloft

My problem is that I can't create a table of contents for my document. I just use

\usepackage{tocloft}
...
  \newpage      
    \tableofcontents

but it's generating nothing but the word "Contents"!
However TeXstudio, in the left sidebar, is showing all sections and stuff.

enter image description here

When I open the .toc file with notepad++ there's only this string

\select@language {russian}

Example

\documentclass[14pt,a4paper]{extarticle}
\usepackage[T2A]{fontenc}
\usepackage[english,russian]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{relsize}
\usepackage{listings}
\usepackage{tocloft}
\usepackage{tocvsec2}


\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}
\lstset{
  language=php,
  numbers=none,
  tabsize=3,
  breaklines=true,
  aboveskip=1ex,
  belowskip=1ex,
  basicstyle=\small\ttfamily,
  framerule=0pt,
  backgroundcolor=\color{gray!10},
  columns=fullflexible,
  showstringspaces=false
}

\begin{document}
    \newpage
        \tableofcontents
\newpage
        \begin{center}
            \section*{Краткая характеристика}
        \end{center}
        В данной работе рассматривается создание и управление базой данных для веб-сайта. На примерах рассмотрена регистрация пользователей на сайте, осуществление восстановления логина/пароля пользователя, так же рассмотрены функции администратора сайта - добавление/удаление информации и объектов.

        Все формы созданы на языке гипертекстовой разметки HTML, для создания сценариев взаимодействия с базами данных используется язык PHP.

        Применяемая СУБД: MySQL.

        Для администрирования СУБД использовалось приложение PHPMyAdmin.

\end{document}

Best Answer

You are using \section*{...}. This will format its text like a section, but the section will not be numbered and it will not be listed in the table of contents. Remove the star, compile twice, and the section should appear in the toc. If you want to have different entries in the toc and in the main text (for example if the section title is much too long for the toc), you can use \section[toc title]{section title}, where "toc title" goes into the toc and "section title" is written in the main text.

As more MWE you could look at

\documentclass{article}
\usepackage{tocloft}
\begin{document}
\tableofcontents
\newpage
\section[Some section title]{\centering Some longer section title}

\section*{\centering Another section title}
\end{document}

and the result when compiling it (twice).

I should also mention \addcontentsline{toc}{section}{section title only in toc} which adds an entry(-line including page number) to the toc (lof would add to the list of figures, lot to tables,...), formatted as section, but would not write anything in the main text.

Related Question