[Tex/LaTex] index show like a section (including section number)

indexing

I like to show the index in the table of contents. The index shall be shown like a section, it is including the section number and then the section name. Also the same when the index is printed at the end of the document. The index shall be printed like a section with section number and a horizontal line under it from left to right.

Here I call the index = "Sache" to have a differentiation to the standard.

What is the best way to do that ?

Thank you and with best regards,
Timo

\documentclass[twoside]{article}

% Packages required by doxygen
\usepackage{calc}
\usepackage{doxygen}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{makeidx}
\usepackage[xindy]{imakeidx}%
\usepackage{multicol}
\usepackage{multirow}
\usepackage{textcomp}
\usepackage[table]{xcolor}

% Font selection
\usepackage[T1]{fontenc}
\usepackage{mathptmx}            % similar to Times New Roman
\usepackage[scaled=.90]{helvet}  % 
\usepackage{courier}             % 
\usepackage{amssymb}
\usepackage{sectsty}
\renewcommand{\familydefault}{\sfdefault}
%
% generate the index \renewcommand{\indexname}{Sache}
\makeindex
\usepackage{geometry}
\geometry{%
  a4paper}
\fancypagestyle{plain}
\usepackage{titletoc}
\usepackage{titlesec}
%
% start every section (in "article" / chapter in "report") with/at a new page
\let\stdsection\section
\renewcommand{\section}{\newpage\stdsection}
%
% define how deep the numbering of the table-of-contents can be 
\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{5}
%
%================================ C O N T E N T S 
\begin{document}
%--- End generated contents by doxygen ---
\section{Sache}
\addcontentsline{toc}{section}{Sache}
% print out the index at the end of the document
\printindex
%
%================================================================================
%
\label{lastpage} % get a label for the last page to be printed in the footer 
%
% print for test purpose the total number of page(s)
{last page : } \pageref{lastpage}

%
\end{document}

Best Answer

Since imakeidx package is used, the intoc option to the \makeindex command should work!

For the appearance as section instead of of unnumbered \section* use the level=\section option of \indexsetup, for the horizontal rule use \indexprologue for example.

Some notes:

  • \renewcommand{\section}{...} looks weird in this context.
  • I had to comment out doxygen and \fancypagestyle{plain}

\documentclass[twoside]{article}

% Packages required by doxygen
\usepackage{calc}
%\usepackage{doxygen}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
%\usepackage{makeidx}  useless in conjunction with imakeidx
\usepackage[xindy]{imakeidx}%
\usepackage{multicol}
\usepackage{multirow}
\usepackage{textcomp}
\usepackage[table]{xcolor}

\makeatletter
%\def\imki@indexlevel{\section}
\makeatother

% Font selection
\usepackage[T1]{fontenc}
\usepackage{mathptmx}            % similar to Times New Roman
\usepackage[scaled=.90]{helvet}  % 
\usepackage{courier}             % 
\usepackage{amssymb}
\usepackage{sectsty}
\renewcommand{\familydefault}{\sfdefault}
%
% generate the index \renewcommand{\indexname}{Sache}

\indexsetup{level=\section}
\indexprologue{\hrule}

\makeindex[intoc]
\usepackage{geometry}
\geometry{%
  a4paper}
%\fancypagestyle{plain}
\usepackage{titletoc}
\usepackage{titlesec}
\usepackage{xpatch}


%
% start every section (in "article" / chapter in "report") with/at a new page
%\let\stdsection\section
%\renewcommand{\section}{\newpage\stdsection}

\xpretocmd{\section}{\clearpage}{}{}

%
% define how deep the numbering of the table-of-contents can be 
\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{5}
%
%================================ C O N T E N T S 
\begin{document}

\tableofcontents
%--- End generated contents by doxygen ---
\section{Sache}
%\addcontentsline{toc}{section}{Sache}
% print out the index at the end of the document
\printindex
%
%================================================================================
%
\label{lastpage} % get a label for the last page to be printed in the footer 
%
% print for test purpose the total number of page(s)
{last page : } \pageref{lastpage}

%
\end{document}

enter image description here