55 Comments

  1. Winkelwagen

    Very well put. It’s much nicer then using a modified \paragraph command to itemize questions and answers in a document.

  2. Hi there,

    Great tip! I have a macro so that I can write a to-do list of things as I go along, and now I’ve used your example to roll in the ability to collate these into a list too.

    Here for all to share:-

    \newcommand{\listtodotitle}{To-do list}
    \newlistof{todos}{tod}{\listtodotitle}
    \newcommand{\todolist}[1]{%
    \refstepcounter{todos}
    \addcontentsline{tod}{todos}
    {\protect\numberline{\thechapter.\thetodos} #1}}
    \newcommand{\todo}[1]{\todolist{#1}\textbf{\underline{TODO}: #1}}

    And then when you are writing and need to make a note, you just need to write \todo{Blah. Something I’ve not done yet}. Of course, you’ll need to put in \listoftodos to print the list also.

    Very handy!

    Thanks,

    Andy

    • YL

      Andy, thanks so much for this reply! I just cut and paste your macro in, and it works like a charm. I found this page on the search for how to make a to do list, and ta da! your reply supplied the answer I needed.

    • Love this solution! I extended it with another piece of code I found, so it now has checkboxes in the “list of..”.

      \usepackage{pifont}
      \usepackage{nameref}
      \newcommand{\cmark}{\ding{51}}%
      \newcommand{\open}{\rlap{$\square$}{\raisebox{2pt}{\large\hspace{1pt}}}%
      \hspace{8.5pt}}
      \newcommand{\done}{\rlap{$\square$}{\raisebox{2pt}{\large\hspace{1pt}\cmark}}%
      \hspace{-2.5pt}}
      
      % For custom "list of xyz"
      \usepackage{tocloft}
      \newcommand{\listtodotitle}{To-do Liste}
      \newlistof{todos}{tod}{\listtodotitle}
      \newcommand{\todolist}[2]{%
      	\refstepcounter{todos}
      	\addcontentsline{tod}{todos}
      	{#2  \nameref{exp\thesection}: \protect#1}
      }
      \newcommand{\todo}[3]{\todolist{#1}{#2}
      	\IfEqCase{#3}{%
      		{h}{}%
      		{v}{\textbf{To-do:} #1\\}%
      	}[\PackageError{tree}{Undefined option to tree: #1}{}]%
      }

      Todos: \todo{Task}{“\done” or “\open”}{“v” or “h”}
      – “\done” leaves a checked square in the list, “open” an unchecked.
      – “v” makes todo appear in the text, “h” hides it.

      Sections must have the label: \label{exp\thesection}
      – You can change exp, but must update it also in the definition of “\todolist”.

      Output of list is like:

      – :…

  3. Steve

    Thanks for the great tutorial!

    I too have defined a new list, but it is a list of acronyms. Now, every time I introduce a new acronym I add it to the list, so as to act as a reference if someone doesn’t want to read my document from the beginning.

    \newcommand{\listacronymname}{List of Acronyms}
    \newlistof{acronyms}{exp}{\listacronymname}
    \newcommand{\acronym}[1]{\textsuperscript{\#}%
    \refstepcounter{acronyms}%
    \addcontentsline{exp}{acronyms}{#1}}

    (in the document)

    I hate WYSIWYG\acronym{WYSIWYG = What You See Is What You Get} editors.

    (at the end of the document}

    \newpage
    \listofacronyms

    Then it prints the list of all acronyms and the page of first appearance! It’s great.

    Thanks for your help,

    Steve

  4. Thanks very much for this! Helps a lot. However, my style file does not seem to interact well with tocloft: when I use it, it distorts the style of headings etc. Any ideas guys? Cheers.

  5. Leoncio Barros

    Very nice. However, I cant include the package in my thesis! Please, is there some compatibility requirement with this package?

  6. Nam Nguyen

    Hello,

    I am writing because I would like to use this method to make a list of “graphs”. I do not know how to take the pictures of my graphs that are in the “figure” environment and list them in the graphs. I do not understand how to go from taking the

    \graph{Your Second Example}

    and turning it into something that will display my graph’s caption in the list of graphs.

    Someone else has done some work with the list of the floats, but the help is incomplete (i.e. without a minimum working example) and the german translation is difficult to read. At the moment, trying to work with your example:

    \documentclass{report}
    \usepackage{tocloft}
    \usepackage[english]{babel}
    \newcommand{\listgraphname}{List of Graphs}
    \newlistof{graph}{gra}{\listgraphname}
    \newcommand{\graph}[1]{%
    \refstepcounter{graph}
    \addcontentsline{gra}{graph}
    {\protect\numberline{\thechapter.\thegraph}#1}\par}
    \begin{document}
    \tableofcontents
    \newpage
    \listofgraph
    \chapter{Two examples}
    \graph{first example}
    \begin{figure}[h]
    \centering
    \includegraphics[scale =0.5]{graph.jpg}
    \caption{Example Graph}
    \label{Fig: 1}
    \end{figure}
    \label{1st_ex}
    \graph{Your second example}
    \label{2nd_ex}
    \chapter{One example}
    \graph{Your third example. (See example \ref{1st_ex} \& \ref{2nd_ex})}
    \end{document}

    With the aim of putting the figure in the list of graphs

    Any help would be greatly appreciated.

    Sincerely,
    N

      • Nam Nguyen

        Hello,

        I have managed to include the figure floats in the List of Graphs. However, I have been unable to change the typeset of the entries in the List of Graphs via:

        \renewcommand{\cftgratitlefont}{\Large \bfseries}
        \newcommand\cftgrapresnum{}
        \newcommand{\cftgraaftersnum}{}
        \renewcommand{\cftgrapresnum}{Graph }
        \renewcommand{\cftgraaftersnum}{:}
        \newcommand{\cftgranumwidth}
        \newlength{\mylen}
        \settowidth{\mylen}{\bfseries\cftgrapresnum\cftgraaftersnum}
        \newcommand{\addtolength}{\cftgranumwidth}{1in}

        as per the tocloft manual’s example. Any help on this matter would be greatly appreciated.

  7. Nam Nguyen

    Hello,

    I am having a bit of an issue with the renaming of the titles of the captions for my new floats in the tocloft package. While the same:

    \renewcommand{cftfigpresnum}{Figure} works,

    my new list won’t allow me to change the name

    new list: graphs, extension {gra}

    \renewcommand{\cftgratitlefont}{\Large \bfseries}
    \newcommand\cftgrapresnum{}
    \newcommand{\cftgraaftersnum}{}
    \renewcommand{\cftgrapresnum}{Graph }
    \renewcommand{\cftgraaftersnum}{:}
    \newcommand{\cftgranumwidth}

    Will still only output the number and the caption, but not “Graph 1”

    Any help would be greatly appreciated.

    Sincerely,
    N

    • Hey Nam,

      Thanks for your comments with the examples. The problem is that the code in the post is for a simple command only. What you need is a new float environment, basically a copy of figure. The trivfloat package provides a simple way to do this. Here is the documentation.

      Hope it works!

      Best, Tom.

      • Nam

        Thank you for you suggestion of trivfloat, however, I still cannot find the proper code to change the listing on the “List of Graphs” from just the number. Any assistance would be appreciated for changing the listing style for trivfloat.

        Sincerely,
        N

      • Nam

        Also, the trivfloat won’t allow the placement of the \caption to govern the placement, as I wish to place it above the graph, but it will not allow me to.

        Below is a working example, showing the position of the caption as well as the output of the list of graphs.

        […] Code remove by Tom […]

      • Hey Nam,

        I removed your code, it was slightly more than the bare minimum, hope you don’t mind :-). Here is a minimal example that should solve both problems, adding the word “Graph” to entries of your list-of-graphs and place the caption above graphs.

        \documentclass{article}
        \usepackage{trivfloat, graphicx, caption}
        \DeclareCaptionType{graph}
        \floatstyle{plaintop}
        \restylefloat{graph}
        \trivfloat{graph}
        \begin{document}
        \renewcommand\numberline[1]{Graph #1:\hspace{1.8em}}
        \listofgraphs
        \clearpage
        \begin{graph}
        \centering
        \caption{My graph}
        \includegraphics[width=0.3\textwidth]{test}
        \end{graph}
        \end{document}

        Two things to note. Firstly, make sure you define \trivfloat{graph} after setting the caption type. Second, create the listoffigures and then do \renewcommand{...}, otherwise the word “Graph” gets added also to lof-entries.

        I found help here and there.

        Cheers, Tom.

  8. Hi, this post is getting old, but I’ll try my luck.

    The code works great, but when I add the list to my toc it is not formatted like the rest of my toc (not correctly indented, not bold faced, etc.)

    I add it to toc by using:

    \addcontentsline{Sequence}{toc}{List of Sequences}

    after

    \listofSequences

    Any help is appreciated!

    • Hi,

      The following line should work. Add it before you create the list to get the page number right (in case the list occupies more than one page).

      \addcontentsline{toc}{chapter}{List of Sequences}

      Best, Tom.

  9. Melinda

    I have been unable to get any of this code to work in my project. I am trying to create a list of equations at the begining of a dissertation.
    I have the following as part of my overall code.

    \usepackage{tocloft}
    \newcommand{\listmyequationsname}{List of Equations}
    \newlistof{myequations}{equ}{\listmyequationsname}
    \newcommand{\myequations}[1]{%
    \refstepcounter{myequations}%
    \par\noindent\textbf{myequations \themyequations. #1}
    \addcontentsline{equ}{myequations}
    {\protect\numberline{\thechaper.\themyequations}#1}\par}
    
    \begin{document}
    
    \begin{romanpages}
    \tableofcontents{}
    
    \listofmyequations
    
    \listoftables
    
    \end{romanpages}
    \include{Chapter1/Introduction}
    \end{document}
    
    In chapter1/introduction, I have the following:
    
    \begin{equation}\label{eq:SOE}
    g(\pi_j)= \alpha_{jk} \alpha_{kg}\theta_g + \alpha_{jk}\xi_k + \beta_j
    \end{equation}
    \myequations{Second Order Equation}

    This will not compile with the “\myequations{Second Order Equation}” included. When I comment that out the List of Equations title is generated, but no equations are listed. What am I missing?

    • Hi Melinda,

      Sorry it took a while. There is just a minor typo in the last argument of \addcontentsline where you typed \thechaper instead of \thechapter. Otherwise, your code is fine.

      Here is your minimal working examples with the typo fixed:

      \documentclass[11pt]{report}
      \usepackage{tocloft}
      
      \newcommand{\listmyequationsname}{List of Equations}
      \newlistof{myequations}{equ}{\listmyequationsname}
      \newcommand{\myequations}[1]{%
      \refstepcounter{myequations}%
      \par\noindent\textbf{Equation \themyequations. #1}
      \addcontentsline{equ}{myequations}
      {\protect\numberline{\thechapter.\themyequations}#1}\par}
      
      \begin{document}
      \tableofcontents
      \listofmyequations
      \listoftables
      \chapter{Introduction}
      \begin{equation}\label{eq:SOE}
      g(\pi_j)= \alpha_{jk} \alpha_{kg}\theta_g + \alpha_{jk}\xi_k + \beta_j
      \end{equation}
      \myequations{Second Order Equation}
      \end{document}
  10. Melinda

    I may be confused but I see a period after \thechapter. in my code and yours. With or without the (.) the file does not compile as long as I have the \myequations tag after the equation. I still do not see a way to get the equations list to populated. Do I need to redefine equation so that it will automaticaly include my \myequations tag?

    • Hi,

      How’s this:

      \documentclass[11pt]{report}
      \usepackage{tocloft}
      
      \newcommand{\listmyequationsname}{List of Equations}
      \newlistof{myequations}{equ}{\listmyequationsname}
      
      % Redefining \theequation to make the entry in the list of equations
      \makeatletter
      \renewcommand\theequation{\ifnum \c@chapter >\z@ \thechapter .\fi \@arabic \c@equation
                                 \protect\refstepcounter{myequations}%
                                  \protect\addcontentsline{equ}{myequations}%
                                  {Eq.~\thechapter.\@arabic\c@equation}%
                                }
      \makeatother
      
      \begin{document}
      \tableofcontents
      \listofmyequations
      \listoftables
      \chapter{Introduction}
      \begin{equation}\label{eq:SOE}
      g(\pi_j)= \alpha_{jk} \alpha_{kg}\theta_g + \alpha_{jk}\xi_k + \beta_j
      \end{equation}
      
      \newpage
      \begin{equation}\label{eq:SE}
      x= y
      \end{equation}
      
      \end{document}
  11. Melinda

    The error that I get is

    ! Undefined control sequence.
    Equations \theequations
    .\@currentlabelname
    1.78 \end{equation}

    I get the above error by adding the following code which I thought maybe I needed so that the list of equations would populate.

    \let\oldequation = \equation
    \let\endoldequation = \endequation
    \renewenvironment{equation}{
        \begin{oldequation}
    }{
        \end{oldequation}
        \myequations{\@currentlabelname}
    }
    • Hi Melinda,

      I see what you are trying to do. The problem is that you want to place \myequations outside the environment. Your code encloses two equation environments.

      Try the code below which uses the xparse package. If it doesn’t work, you might have to update to the latest version of LaTeX. It creates a new environment myequation taking care of the label as well as producing the caption/list entry. ‘m’ stands for mandatory argument. You can make them optional using ‘o’. See this article on xsparse for some more details.

      Hope it helps,
      Tom

      \documentclass[11pt]{report}
      \usepackage{tocloft, xparse}
      
      \newcommand{\listmyequationsname}{List of Equations}
      \newlistof{myequations}{equ}{\listmyequationsname}
      \newcommand{\myequations}[1]{%
      \refstepcounter{myequations}%
      \par\noindent\textbf{Equation \themyequations. #1}
      \addcontentsline{equ}{myequations}
      {\protect\numberline{\thechapter.\themyequations}#1}\par}
      
      \DeclareDocumentEnvironment{myequation}{ m m }{%
      \equation\label{#1}}{\endequation\myequations{#2}}
      
      \begin{document}
      \tableofcontents
      \listofmyequations
      \listoftables
      \chapter{Introduction}
      \begin{myequation}{eq:SOE}{Second Order Equation}
      g(\pi_j)= \alpha_{jk} \alpha_{kg}\theta_g + \alpha_{jk}\xi_k + \beta_j
      \end{myequation}
      \end{document}
      • melinda

        I was able to get the the list of equations to compile but I now need to change the font of the title List of Equations. I have used :

        \renewcommand{cft X titlefont}{\Large\bfseries} for other titles but I don’t know what to put in the X for myequations. I have tried LoE, and LME. Any idea?

      • Hi Melinda,

        Thanks for your question. I took this from the tocloft documentation on page 14. Using the example from my post above, you could change the font as follows (X: example, Z: exp):

        %From documentation
        \newlistof{X}{Z}{...}
        \cftZtitlefont
        
        %My example
        \newlistof{example}{exp}{\listexamplename}
        \renewcommand{\cftexptitlefont}{\Large\bfseries}

        Make sure you don’t forget the backslash when you redefine the command.

        Cheers, Tom

      • Melinda

        Thanks for your help with the font on myequations. I think I was trying to change the font too early in the code – before I defined myequations. Once I moved that line, and changed it as you suggested, it worked. Here is the code that worked.

        % redefine equation to automatically include our \myequations tag
        \let\oldequation = \equation
        \let\endoldequation = \endequation
        \AtBeginDocument{\let\oldlabel = \label}
        \newcommand{\mynewlabel}[1]{\myequations{#1}\oldlabel{#1}}
        \renewenvironment{equation}{%
         \oldequation
        \let\label\mynewlabel
        }{\endoldequation}
        
        \newcommand{\listequationsname}{List of Equations}
        \newlistof{myequations}{equ}{\listequationsname}
        \newcommand{\myequations}[1]{%
        \addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}}
        \setlength{\cftmyequationsnumwidth}{3em}
        \renewcommand{\cftequtitlefont}{\Large\bfseries}
  12. I get the following error, when I try to compile the following code.
    Missing \begin{document}

    \documentclass{report}
    \usepackage{tocloft}
    \newcommand{\listofabbreviations}{List of Abbreviations}
    \newlistof{abbreviations}{abb}{\listofabbreviations}
    \newcommand{\abbreviation}
    \refstepcounter{abbreviations}
    \par\noindent\textbf{ Abbreviation \theabbreviation. #1}
    \addcontentsline{abb}{abbreviation}
    {\protect\numberline{\thechapter.\theabbreviation}#1}\par}
    \tableofcontents
    \clearpage
    \listofabbreviations
    \begin{document}
    Land use and land cover are commonly referred to as LULC\abbreviation{LULC=Land Use and Land Cover}.
    \end{document}
    
      • There were a few other minor issues in your code. I corrected it below. Consider using the nomencl package instead.

        \documentclass{report}
        \usepackage{tocloft}
        \newcommand{\listabbreviationname}{List of Abbreviations}
        \newlistof{abbreviations}{abb}{\listabbreviationname}
        \newcommand{\abbreviations}[1]{%
        \refstepcounter{abbreviations}
        \par\noindent\textbf{Example \theabbreviations. #1}
        \addcontentsline{abb}{abbreviations}
        {\protect\numberline{\thechapter.\theabbreviations}#1}\par}
        \begin{document}
        \tableofcontents
        \clearpage
        \listofabbreviations
        \chapter{Dummy chapter}
        Land use and land cover are commonly referred to as LULC\abbreviations{LULC=Land Use and Land Cover}.
        \end{document}
    • Hi,

      Thanks for the code. Move the three highlighted lines into the document content and your code should work fine. You can define commands in the preamble, but producing the lists has to be done later.

      HTH, Tom

      • I moved the table of contents after

        \begin{document}
        

        But I still get the same error. And the compilation stops at

        \refstepcounter{abbreviations}
        

        Any idea as to why this is happening?

      • The reason being that there are a few more typos on your code. E.g. line 3, \listofabbreviations should be \listabbreviationname. Start from the code I posted here, it works.

        Best, Tom.

  13. fredFarzad

    Hi,

    I have a question about creating a customized toc. My goal is to define a new item called, \newitem, which has the following 4 entries,

    \newitem{category}{style}{ref}{title}

    The category and style is from the limited list. For example, in my case, category can be: spin, CQED, general and style is: Paper, thesis, lecture, website.

    Now my goal is to list the given item according to category and style, as following,

    Spin
    Thesis
    1
    2
    ….
    Lecture
    4
    5
    ….
    CQED
    Thesis
    101
    102
    ….
    Papers
    304
    ….

    And finally make a bibtex from the “ref” input (this is not very essential).

    Thanks,
    Farzad.

    • Hey!

      Thanks for your question. A custom list as defined by tocloft takes one parameter only, the title. So you’d probably get 4 different lists, one for each category. If you need to implement it exactly as described, you might have to consider another approach. An alternative approach would be to stick to a single list and mark the titles, e.g. [general, paper] Title…. This can be done in an automated way using the approach discussed in the post.

      Best, Tom

      • Thanks for your response, although I am not sure yet how to do it. I will play a little bit and ask you again, if I could not succeed. By the way, I was wondering where can I find the list of syntax for preamble and their functionality? I use Latex for a long time, but I am pretty new to writing something in the Preamble myself. When I look at the template cls file, they are full of signs, and abbreviation which I have no clue about. How can I go ahead and learn about writing my own template for latex.

        It has been a long time that i am searching for a digital notebook which is LaTex friendly. However, I have not been successful yet. I desire to write a template similar to the Microsoft’s onenote.

        Thanks again, Farzad.

      • Hi fred,

        Sure, let me know if you need additional help.

        Concerning LaTeX resources, the “LaTeX companion” is the reference book and you might consider buying a copy. Otherwise, I can suggest searching online resources such as tex.SX.

        There is also a package/class writing guide which you might find useful.

        HTH, Tom.

      • I should probably add that what you describe as “signs and abbreviations” is most likely TeX rather than LaTeX. Look for the TeXbook if you’d like to know more. Tom.

      • Hi Tom,

        Sorry to bother you. I was wondering how can I add “\the” to some input variable. For example, I like to use

        \newcommand{\add}[1]{ \chapter{#1} \def\thechapter{\the#1} }

        where I previously defined some counters. I searched for a while but I could not find any! Cheers, Farzad.

      • I’m not quite sure what you are trying to do. However, you don’t have to set the counter manually. It’s automatically incremented by 1 when you do \chapter. If you’d like to refer to a specific chapter, use \label and \ref.

        Hope this helps, Tom.

  14. Hi there,

    Thank you to everyone for posting their code and explanations. I am new to LaTex and am having difficulty formatting my MA thesis, a case study in the social sciences.

    I am trying to make a “List of Songs” to follow my List of Tables and List of Figures. Ideally, the List of Songs would pull from songs within different sections of the article.

    I’ve tried to adapt what’s listed above, but am running into trouble executing (and perhaps defining) \song. Also, is it a problematic that 1) I am in an article (not report) documentclass and 2) the .tex file will not recognize \refstepcounter, but will recognize \ref ?

    Here’s a copy of my code thus far…

    \documentclass{article}
    \usepackage{tocloft}
    \usepackage[english]{babel}
    
    \newcommand{\listsongname}{List of Songs}
    \newlistof{songs}{s}{\listsongname}
    \newcommand{\song}[1]{%
    \ref{songs}
    \addcontentsline{s}{songs}
    {\protect\numberline{\chapter.\thesongs}#1}}
    
    \begin{document}
    \tableofcontents
    
    \listofsongs
    
    \section{Methodology}
    
    \song{Calm or Alarmed}
    song text here
    
    \end{document}

    The output…

    – Creates a List of Songs with “.0 Calm or Alarm” listed properly across from the page number. But, how can I number it properly with a sequential number preceding the period?

    – Lists “??[1] yippee” under the section … I’m not sure how to define and execute \song

    • tom

      Hi Cece,

      Sorry for the delay. I hope this is still relevant. You almost got it right, I updated your code below. To print a counter value, use \thecounter. So, \thesection.\thesongs would be what you want here. On my system \refstepcounter works. The code also prints a basic title along with the text now. Let me know if you need any more help.

      Best, Tom

      \documentclass{article}
      \usepackage{tocloft}
      \usepackage[english]{babel}
      
      \newcommand{\listsongname}{List of Songs}
      \newlistof{songs}{s}{\listsongname}
      \newcommand{\song}[2]{%
      \refstepcounter{songs}
      \par\noindent\textbf{\thesongs. #1:}~#2
      \addcontentsline{s}{songs}
      {\protect\numberline{\thesection.\thesongs}~#1}}
      
      \begin{document}
      \tableofcontents
      \listofsongs
      \section{Methodology}
      \song{Calm or Alarmed}{song text here}
      
      \section{Second}
      \song{Other song}{song text here}
      
      \end{document}
  15. Vladimir

    Hi,

    thanks for your tutorial.

    I made my list of revisions, so at the end of the document is list:

    Revision history

    1 Some material change, app. by Mr. X, Company X – Town X, 2019-07-11………………….2
    2 Some dimension change, app. by Mr. Y, Company Y – Town Y, 2018-05-03……………….3
    3 Some temperature change, app. by Mr. Z, Company Z – Town Z, 2015-03-12……………6
    …etc…

    Here is code:

    \newcommand{\listrevisionname}{Revision history}
    \newlistof{revision}{numb}{\listrevisionname}
    
    \newcommand{\revision}[4]{%
    \refstepcounter{revision}
    %\par\noindent{(rev.\therevision #1)}
    {(rev. {\therevision})}
     \addcontentsline{numb}{revision} 
    {\protect\numberline{\therevision}\textit{#1}, #2, #3, #4 }\par
    
    }

    Material: Steel \revision{Some material change}{app. by Mr. X}{Company X - Town X}{2019-07-11}

    Please, is there way to sort/order this list by date?

    Thanks

Leave a Reply