[Tex/LaTex] Manipulating list of figures

table of contentstocloft

To list my figures, I used \listoffigures and the result looks like

1.1 xyza ......... 12
1.2 abc2 ......... 14
2.1 bacd ......... 17
2.2 bace ......... 18
.
.
.
6.1 xxxx ......... 40

However, I am trying to list my figures like

Figure 1 xyza ......... 12
Figure 2 abc2 ......... 14
Figure 3 bacd ......... 17
Figure 4 bace ......... 18
.
.
Figure n xxxx ......... 40

For this I tried the following:

\usepackage{tocloft}
\renewcommand{\cftfigfont}{Figure }

This adds ‘Figure ’ before 1.1, 1.2 2.1, 2.2, . . ., 6.1. To change (1.1, 1.2, 2.1, 2.2, . . ., 6.1) to (1, 2, 3, . . ., n) in the list of figures, I tried using

\renewcommand{\thefigure}{\arabic{figure}.}

and it do changes to 1, 2, 3, . . . But the numbering 1, 2, 3, . . . again starts when a new chapter starts and moreover the entries in the figure caption also changes which I don't want. So, how to get a continuous figure number, irrespective of chapter in the list of figures and without any changes in the figure caption.

Best Answer

The macro \mycaption uses \thefigure for captions and \arabic{figure} for the lof (plus a few other formatting changes). Note that \@captype can be figure or table.

\documentclass{article}
\usepackage{caption}% required

\makeatletter
\newcommand{\mycaption}[2][\@empty]% #1 = short caption (optionl), #2 = caption
{\refstepcounter\@captype
 \caption@caption*{\csname fnum@\@captype\endcsname{: }#2}%
 \ifx\@empty#1
   \addcontentsline{\csname ext@\@captype\endcsname}{\@captype}%
     {\csname\@captype name\endcsname\space\arabic{\@captype}: #2}%
 \else
   \addcontentsline{\csname ext@\@captype\endcsname}{\@captype}%
     {\csname\@captype name\endcsname\space\arabic{\@captype}: #1}%
 \fi
}
\makeatother

\begin{document}

\listoffigures

\begin{figure}
\renewcommand{\thefigure}{1.1}%
\caption{normal caption}

\renewcommand{\thefigure}{2.6}%
\mycaption{my caption}
\end{figure}

\end{document}

demo


If you don't want to rename all your \captions to \mycaption, just use

\let\caption=\mycaption

instead. However, \caption* will no longer work.


Odds are the figure counter is being reset to 0 at the start of each chapter, in which case you will need to use a different counter.

\newcounter{myfigure}
\newcounter{mytable}

\makeatletter
\newcommand{\mycaption}[2][\@empty]% #1 = short caption (optionl), #2 = caption
{\refstepcounter\@captype
 \caption@caption*{\csname fnum@\@captype\endcsname{: }#2}%
 \stepcounter{my\@captype}%
 \ifx\@empty#1
   \addcontentsline{\csname ext@\@captype\endcsname}{\@captype}%
     {\csname\@captype name\endcsname\space\arabic{my\@captype}: #2}%
 \else
   \addcontentsline{\csname ext@\@captype\endcsname}{\@captype}%
     {\csname\@captype name\endcsname\space\arabic{my\@captype}: #1}%
 \fi
}
\makeatother

Finally, I despise this programming style, as it is almost unreadable. So for my own peace of mind:

\makeatletter
\def\mycaption{\csname\@captype @caption\endcsname}

\newcommand{\figure@caption}[2][\@empty]% #1 = short caption(optional), #2 = caption
{\refstepcounter{figure}%
 \caption@caption*{\fnum@figure{: }#2}%
 \stepcounter{myfigure}%
 \ifx\@empty#1
   \addcontentsline{lof}{figure}{\figurename\space\arabic{myfigure}: #2}%
 \else
   \addcontentsline{lof}{figure}{\figurename\space\arabic{myfigure}: #1}%
 \fi
}
\newcommand{\table@caption}[2][\@empty]% #1 = short caption(optional), #2 = caption
{\refstepcounter{table}%
 \caption@caption*{\fnum@table{: }#2}%
 \stepcounter{mytable}%
 \ifx\@empty#1
   \addcontentsline{lot}{table}{\tablename\space\arabic{mytable}: #2}%
 \else
   \addcontentsline{lot}{table}{\tablename\space\arabic{mytable}: #1}%
 \fi
}
\makeatother