List of Tables (LoT) showing up in Table of Contents but LoT is empty

table of contents

I wanted to add the \listoffigures and \listoftables to my table of contents. I found this post where a user shared his/her code to add the \listoffigures. I implemented it and it worked as intendend. I then proceeded to replace "figure" with "table" to hopefully get the same result but for the list of tables. Even though the ToC looked as intended, the actual list of tables at the end of my document was empty. Now I am here writing this post.

This is the code that I copy+pasted to successfully add the listoffigures to my ToC:

\newcommand{\insertfigure}{\begin{figure}\caption{A figure caption}\end{figure}}
\makeatletter
\renewcommand\listoffigures{%
    \section{\listfigurename}% Used to be \section*{\listfigurename}
      \@mkboth{\MakeUppercase\listfigurename}%
              {\MakeUppercase\listfigurename}%
    \@starttoc{lof}%
    }

The following is my modified code (figure->table) that I had hoped would work for the list of tables, but as outlined above, doesn't:

\newcommand{\inserttable}{\begin{table}\caption{A table caption}\end{table}}
\makeatletter
\renewcommand\listoftables{%
    \section{\listtablename}% Used to be \section*{\listfigurename}
      \@mkboth{\MakeUppercase\listtablename}%
              {\MakeUppercase\listtablename}%
    \@starttoc{lof}%
   }

This is the result I would like, but the actual list of tables should also appear at the end of my document:

enter image description here

Translation:

  • B. Appendix 2
  • B.1. List of figures
  • B.2. List of tables

Any suggestions?

Best Answer

You must use \@starttoc{lot} (lot is list of tables) instead of \@starttoc{lof} (lof is list of figures).