[Tex/LaTex] Formatting new list of definitions with tocloft

indentationnumberingtable of contentstocloft

Using the tocloft package in LaTeX, I created a List of Definitions. From the package documentation and some online examples I came up with:

\newcommand{\listdefinitionname}{My list of definitions}
\newlistof{definition}{def}{\listdefinitionname}
\newcommand{\definition}[1]{%
\refstepcounter{definition}
\par\noindent\textbf{TheDefinition \thedefinition. #1}
\addcontentsline{def}{definition}
{\protect\numberline{\thechapter.\thedefinition}#1}\par}

\listofdefinition
  1. In the "My list of definitions" that is created, for all definitions, the first letter of a definition name superposes the last digit in the definition number. How can I fix this?

  2. The numbering seems to be wrong. If I try \newlistof[chapter]{definition}{def}{\listdefinitionname}, the definitions throughout 5 chapters are numbered smth like 1.1.1.1,.. 3.3.3.8.. etc. I would like to obtain the numbering from the List of figures, chapternumber.figurenumber, where figurenumber starts with 1 for every new chapter.

  3. \listoffigures issues a list of figures, indented by about 1 cm from the left. With \listofdefinition the entries begin right at the left margin. How can I get the List of figures formatting for the list of definitions?

Best Answer

The following minimal example works for me in terms of the book document class:

enter image description here

\documentclass{book}
\usepackage{tocloft}% http://ctan.org/pkg/tocloft
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox

\newcommand{\listdefinitionname}{My list of definitions}
\newlistof{definition}{def}{\listdefinitionname}
\newcommand{\definition}[1]{%
  \refstepcounter{definition}%
  \par\noindent\textbf{The Definition~\thedefinition. #1}%
  \addcontentsline{def}{figure}
    {\protect\numberline{\thechapter.\thedefinition}#1}\par%
}
\makeatletter
\preto\chapter{\addtocontents{def}{\protect\addvspace{10\p@}}}%
\makeatother

\begin{document}

\listoffigures
\listofdefinition
\chapter{A chapter}
\begin{figure}\caption{Some figure}\end{figure}
\begin{figure}\caption{Some figure}\end{figure}
\definition{Some definition}
\begin{figure}\caption{Some figure}\end{figure}
\definition{Some definition}
\begin{figure}\caption{Some figure}\end{figure}
\definition{Some definition}

\chapter{A chapter}
\begin{figure}\caption{Some figure}\end{figure}
\begin{figure}\caption{Some figure}\end{figure}
\definition{Some definition}
\begin{figure}\caption{Some figure}\end{figure}
\definition{Some definition}
\begin{figure}\caption{Some figure}\end{figure}
\definition{Some definition}

\end{document}

Regarding your list of questions:

  1. I've inserted the definition entries to be type figure rather using

    \addcontentsline{def}{figure}
      {\protect\numberline{\thechapter.\thedefinition}#1}\par%
    

    That way they are formatted similarly, avoiding any overlap. If you have more definitions and still overlap, you need to change the width of the column.

  2. My numbering works. You could also use \arabic{chapter}.\thedefinition or even \arabic{chapter}.\arabic{definition} which should strip any inherited counters attached to \thechapter or \thedefinition.

  3. Solved via (1.) above.

I've also used the etoolbox package to add a vertical space between the chapter-separated definitions, similar to that of the LoF and LoT. This was done using \preto\chapter{<stuff>} which adds <stuff> before \chapter. Here stuff is \addvspace{10\p@} which adds a maximum of 10\p@ (10pt) vertically.

Related Question