# How to make a combined “List of Figures and Tables”?

I am aware of Combined List of Figures and Tables?, but the asker there requires one numbering scheme for figures and tables, which I don't want. Unfortunately, the answer seems to depend on that prerequisite.

My question is about an intended result/output like:

# List of figures and tables

Figure 1: Map of trees in New Orleans .................................... 3

Figure 2: Number of leaves falling leaves per day ................... 5

Table 1:   Kinds of trees ........................................................ 12

Figure 3: Air quality reduction per 1000 fallen leaves ............ 20

For this to work, redefining figures to be tables (or the other way around) as suggested in the link above (i.e. something like \let\figure\table\let\endtable\endfigure) doesn't work because it of course causes all figures to be called "Table x" as well...

• No, the portion of \caption code which uses \addcontentsline{lof}{section}{your caption} must be changed either to use lof or lot then or use a completely new type lft (list of figures and tables), but regardless, it requires some work to do – user31729 Aug 3 '15 at 17:59
• I think I've got a very simple answer, but could you please provide a minimal working example so that I can test it on your own code? – yo' Aug 3 '15 at 18:15
• Sorry, not "very" simple, just "reasonably" simple :-) – yo' Aug 3 '15 at 18:32

This works. The code is well commented so I don't think any more comments are needed.

\documentclass{article}

% To make the page shorter
\pagestyle{empty}
\textheight3in

% CODE STARTS HERE
% Based on tocloft package
\usepackage[titles]{tocloft}
\newlistof{figtab}{loft}{List of Figures and Tables}
\makeatletter
% Change the file extension of both lot and lof
\def\ext@figure{loft}
\def\ext@table{loft}
% Store the original \thefigure and \thetable
\let\tohe@thefigure\thefigure
\let\tohe@thetable\thetable
% Redefine them to contain a "dummy" \tohe@list...
\def\thefigure{\tohe@listfig\tohe@thefigure}
\def\thetable{\tohe@listtab\tohe@thetable}
% Make the two dummy commands truly dummy
\let\tohe@listfig\relax
\let\tohe@listtab\relax
% Store the original \listoffigtab
\let\tohe@listoffigtab\listoffigtab
% Redefine it in such a way that the dummy commands insert "Fig." or "Tab." respectively
\def\listoffigtab{%
\begingroup
\def\tohe@listfig{Fig.~}
\def\tohe@listtab{Tab.~}
\tohe@listoffigtab
\endgroup
}
% Change \listoffigtab spacing
\setlength{\cftfignumwidth}{5em}
\setlength{\cfttabnumwidth}{5em}
\setlength{\cftfigindent}{0pt}
\setlength{\cfttabindent}{0pt}
\makeatother
% CODE ENDS HERE

\begin{document}

\listoffigtab

% !b just to make the floats appear on the bottom of the first page
\begin{figure}[!b]
\caption{First}
\end{figure}

\begin{table}[!b]
\caption{Little Table}
\end{table}

\begin{figure}[!b]
\caption{Second}
\end{figure}

\end{document}

• Impressive, most impressive ;-) (+1) – user31729 Aug 3 '15 at 19:43

The relevant command is, as 'always' \addcontentsline.

figure and table captions are written to a file whose extension is stored in \ext@figure or \ext@table.

In \@caption (the internal processor macro actually) we find:

\long\def\@caption#1[#2]#3{%
\par
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
\begingroup
\@parboxrestore
\if@minipage
\@setminipage
\fi
\normalsize
\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
\endgroup}


The first parameter of \@caption is the name of the float, i.e. figure or table (usually). This can be used and patched, grabbing the table captions and redirect them to the file with extension \ext@figure.

\documentclass{book}

\usepackage{caption}
\usepackage{xstring}
\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@caption}{%
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
}{%
\IfStrEq{#1}{table}{% Filter table out
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
}{%
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
}%
}{\typeout{Patch success}}{}
\makeatother

\renewcommand{\listfigurename}{List of Figures and Tables}

\begin{document}
\listoffigures
\begin{figure}
\caption{first figure}
\end{figure}

\begin{figure}
\caption{Another first figure}
\end{figure}

\begin{table}
\caption{first table}
\end{table}

\chapter{Another chapter}
\begin{table}
\caption{Yet another table}
\end{table}

\end{document}


A small update after yo' correctly noticed that it's unclear whether it's a table or figure in the LOFT:

\documentclass{book}

\usepackage{caption}
\usepackage{xstring}
\usepackage{tocloft}
\usepackage{xpatch}

% Prepend the tab or fig number with a \makebox (for equal width) and put Tab. or Fig. in there. Change the names at will
\renewcommand{\cfttabpresnum}{\makebox[30pt][l]{Tab.}}
\renewcommand{\cftfigpresnum}{\makebox[30pt][l]{Fig.}}

\makeatletter
\xpatchcmd{\@caption}{%
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
}{%
\IfStrEq{#1}{table}{%
{\protect\numberline{\csname the#1\endcsname\hfill\hspace{1em}}{\ignorespaces #2}}%
}{%
\IfStrEq{#1}{figure}{%
{\protect\numberline{\csname the#1\endcsname\hfill\hspace{1em}}{\ignorespaces #2}}%
}{%
{\protect\numberline{\csname the#1\endcsname}{ \ignorespaces #2}}%
}
}%
}{\typeout{Patch success}}{}
\makeatother

\renewcommand{\listfigurename}{List of Figures and Tables}

\begin{document}
\listoffigures
\begin{figure}
\caption{first figure}
\end{figure}

\begin{figure}
\caption{Another first figure}
\end{figure}

\begin{table}
\caption{first table}
\end{table}

\chapter{Another chapter}
\begin{table}
\caption{Yet another table}
\end{table}

\section{First section}
\subsection{First subsection}
\subsubsection{First subsubsection}
\begin{table}
\caption{Yet another another table}
\end{table}

\end{document}


• Nice as well. The biggest problem now is to know what is a figure and what is a table... – yo' Aug 4 '15 at 6:28
• @yo': That's true. I think, I can add some stuff for that ;-) – user31729 Aug 4 '15 at 7:00
• @yo': Appended (or prepended ;-) Tab. and Fig. for the combined LOFT list` – user31729 Aug 4 '15 at 20:04