TransWikia.com

Formatting new list of definitions with tocloft

TeX - LaTeX Asked by laailalalaa on January 20, 2021

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}
parnoindenttextbf{TheDefinition thedefinition. #1}
addcontentsline{def}{definition}
{protectnumberline{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?

2 Answers

documentclass[11pt]{report}
usepackage{tocloft, xparse}

newcommand{listexamplename}{List of Equations}
newlistof{example}{exp}{listexamplename}
newcommand{example}[1]{%
    refstepcounter{example}%
    parnoindenttextbf{Equation theexample. #1}
    addcontentsline{exp}{example}
    {protectnumberline{thechapter.theexample}#1}par}

DeclareDocumentEnvironment{examplee}{ m m }{%
    equationlabel{#1}}{endequationexample{#2}}

begin{document}
    tableofcontents
    listofexample
    listoftables
    chapter{Introduction}
    begin{examplee}{eq:SOE}{Second Order Equation}
        g(pi_j)= alpha_{jk} alpha_{kg}theta_g + alpha_{jk}xi_k + beta_j
    end{examplee}

end{document}

Answered by J.R on January 20, 2021

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}%
  parnoindenttextbf{The Definition~thedefinition. #1}%
  addcontentsline{def}{figure}
    {protectnumberline{thechapter.thedefinition}#1}par%
}
makeatletter
pretochapter{addtocontents{def}{protectaddvspace{10p@}}}%
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}
      {protectnumberline{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 pretochapter{<stuff>} which adds <stuff> before chapter. Here stuff is addvspace{10p@} which adds a maximum of 10p@ (10pt) vertically.

Answered by Werner on January 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP