25

I'm using the caption package. In the List-Of-Figures I get only the numbers, but I also want to have the prefix. It currently looks like that:

List of Figures
1 Caption of Figure 1........1
2 Caption of Figure 2........9

And I want it to look like:

List of Figures
Figure 1: Caption of Figure 1...1
Figure 2: Caption of Figure 2...9

The same format is already used for the captions themselves.

Hendrik Vogt
  • 37,935
MiKa
  • 473

4 Answers4

27

You could use the tocloft package; an example:

\documentclass{book}
\usepackage{tocloft}

\newlength{\mylen}

\renewcommand{\cftfigpresnum}{\figurename\enspace}
\renewcommand{\cftfigaftersnum}{:}
\settowidth{\mylen}{\cftfigpresnum\cftfigaftersnum}
\addtolength{\cftfignumwidth}{\mylen}

\begin{document}

\listoffigures
\begin{figure}[!ht]
  \centering
  \rule{2cm}{2cm}
  \caption{test figure one}
  \label{fig:test1}
\end{figure}
\begin{figure}[!ht]
  \centering
  \rule{2cm}{2cm}
  \caption{test figure two}
  \label{fig:test2}
\end{figure}

\end{document}

If you want tocloft to use default LaTeX formatting (so it won't "mess up" for example the layout of your table of contents and so on) you can use the titles option of the package:

\usepackage[titles]{tocloft}
nyrtzi
  • 3
  • 1
Gonzalo Medina
  • 505,128
  • This works well, except that tocloft seems to ruin the format of LOF and LOT. But I will figure that out. Thank you very much. – MiKa Mar 07 '11 at 18:00
15

To achieve what you're aiming for without loading the tocloft package, one has to patch an instruction in LaTeX's internal \@caption macro and redefine the internal macros \l@figure and \l@table.

The following MWE shows how to do this; note that the patching is done with the command \patchcmd provided by the etoolbox package. (If, for some reason, you don't want to use the \patchcmd instruction, you will need to copy and paste the entire definition of \@caption from the file latex.ltx into your preamble and replace the string \csname the#1\endcsname with \csname fnum@#1\endcsname:, leaving the other instructions unchanged.)

\documentclass{article}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@caption}{\csname the#1\endcsname}{\csname fnum@#1\endcsname:}{}{}
\renewcommand*\l@figure{\@dottedtocline{1}{1.5em}{4.5em}} % default for 3rd arg: 2.3em
\let\l@table\l@figure % as in article.cls
\makeatother

\begin{document}
\listoffigures
\listoftables

\begin{figure}[h]
\caption{A figure}
\centering xyz
\end{figure}

\begin{table}[h]
\caption{Some table}
\centering abc
\end{table}
\end{document}

enter image description here

Mico
  • 506,678
  • Why would want not to use tocloft? – Martin Schröder Jan 23 '12 at 20:03
  • 2
    @MartinSchröder well, it's giving me an error in Overleaf when I try to use it. – Seanny123 Mar 30 '15 at 01:41
  • @Seanny123 - Please provide more information about the document class you use, how you load the tocloft package, and the error(s) you get. – Mico Mar 30 '15 at 01:50
  • I'm sorry but it doesn't effect with longtable. How can I fix it? – Yuri Apr 11 '17 at 03:54
  • @Yuri - Please tell me how you start a longtable environment. Also, which document class do you use? – Mico Apr 11 '17 at 04:41
  • I replace table by longtable and remove option [h] in your MWE above. You can try on this :D – Yuri Apr 11 '17 at 06:48
  • @Yuri - What exactly do you mean by "replace"? Are you simply writing \begin{longtable}? If so, there's zero chance of success. You must write something like \begin{longtable}{llll}, where llll is the column specification. Do please familiarize yourself with the syntax of the longtable environment. – Mico Apr 11 '17 at 08:55
  • @Mico Yes, I begin longtable with \begin{longtable}{p{5cm}} and finish with \end{longtable}. Don't forget use longtable package. I have a result without "Table" word in List of tables. – Yuri Apr 11 '17 at 09:17
  • @Yuri - Based on the fragmented pieces of information you've provided so far, I have neither a good enough idea of what's going on nor a solid understanding of what you're trying to achieve. Please post a new query to state what you're trying to achieve and what you've tried so far. – Mico Apr 11 '17 at 09:20
  • @Yuri - I don't think this is something that can be solved in the chat room. That's why I asked you to take the time to put together a new query. – Mico Apr 11 '17 at 09:34
  • This doesn't work if hyperref is used. –  Aug 18 '17 at 01:09
  • @Joseph - The solution I posted works just fine with hyperref as long as hyperref is loaded last -- which one should pretty much always to anyway. The main exception is the cleveref package, which must be loaded after hyperref. – Mico Oct 31 '19 at 21:20
  • @Mico Your solution didn't work for me for some reason... – DGuys Dec 06 '23 at 11:38
  • @DGuys - Sorry, but a claim such as "[y]our solution didn't work for me for some reason" is not actionable. Please be a lot more specific as to what isn't working. Did you get any error and/or warning messages? If so, what do these messages say? Do you maybe use a nonstandard document class? – Mico Dec 06 '23 at 13:09
7

When you caption your figure, there's an optional argument that's designed for the list of figures.

\caption[short title]{Long caption describing the figure.}

This will display the short title as the title in the list of figures, and the long caption as the actual caption of your figure. It is perfectly acceptable for these both to be the same.

It is designed this way as many figures, particularly in scientific publications have long captions describing everything that is in the figure. All of this wouldn't fit into the list of figures, so there is a separate title for that purpose.

It is optional because you don't need it if you are not including a list of figures.

Hendrik Vogt
  • 37,935
Heather
  • 836
  • Just noticed that you're using the caption package, what I have described is the default. I would guess that the syntax for the caption package is similar (if not exactly the same). – Heather Mar 07 '11 at 16:45
  • 1
    a tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button (with "101010" on it). – Hendrik Vogt Mar 07 '11 at 17:17
  • Thank you very much @Dom, but that's not what I'm looking for. – MiKa Mar 07 '11 at 18:00
  • Sorry @MiKa, just re-read, and realised I hadn't understood the question, oh well. Thanks for the pointer on how to make it look like code @Hendrik Vogt. – Heather Mar 07 '11 at 21:49
  • no problem, luckily somebody found a solution to my problem. Thanks for trying!!! – MiKa Mar 08 '11 at 12:08
5

You can also use package tocbasic:

\documentclass{article}
\usepackage{tocbasic}

\DeclareTOCStyleEntry[
  entrynumberformat=\entrynumberwithprefix{\figurename},
  dynnumwidth,
  numsep=1em
]{tocline}{figure}
\newcommand\entrynumberwithprefix[2]{#1\enspace#2:\hfill}

\begin{document}
\listoffigures
\begin{figure}[!ht]
  \centering
  \rule{2cm}{2cm}
  \caption{test figure one}
  \label{fig:test1}
\end{figure}
\begin{figure}[!ht]
  \centering
  \rule{2cm}{2cm}
  \caption{test figure two}
  \label{fig:test2}
\end{figure}
\end{document}

Run three times to get

enter image description here

Or with a KOMA-Script class:

\documentclass[listof=entryprefix]{scrartcl}% loads tocbasic automatically
\AfterTOCHead[lof]{\def\autodot{:}}

\begin{document}
\listoffigures
\begin{figure}[!ht]
  \centering
  \rule{2cm}{2cm}
  \caption{test figure one}
  \label{fig:test1}
\end{figure}
\begin{figure}[!ht]
  \centering
  \rule{2cm}{2cm}
  \caption{test figure two}
  \label{fig:test2}
\end{figure}
\end{document}

enter image description here

esdd
  • 85,675
  • is it possible to do this with tables we well? – Austin Benny Oct 07 '21 at 23:45
  • @AustinBenny Of course it is possible with tables as well. In the first example you have to add \DeclareTOCStyleEntry[entrynumberformat=\entrynumberwithprefix{\tablename}, dynnumwidth, numsep=1em]{tocline}{table} and in the second (using a KOMA-Script class) \AfterTOCHead[lot]{\def\autodot{:}}. – esdd Oct 08 '21 at 11:58