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.

0

4 Answers 4

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}
1
  • 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 7, 2011 at 18:00
14

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

13
  • Why would want not to use tocloft? Jan 23, 2012 at 20:03
  • 2
    @MartinSchröder well, it's giving me an error in Overleaf when I try to use it.
    – Seanny123
    Mar 30, 2015 at 1: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, 2015 at 1:50
  • I'm sorry but it doesn't effect with longtable. How can I fix it?
    – Yuri
    Apr 11, 2017 at 3:54
  • @Yuri - Please tell me how you start a longtable environment. Also, which document class do you use?
    – Mico
    Apr 11, 2017 at 4:41
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.

5
  • 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).
    – Dom
    Mar 7, 2011 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). Mar 7, 2011 at 17:17
  • Thank you very much @Dom, but that's not what I'm looking for.
    – MiKa
    Mar 7, 2011 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.
    – Dom
    Mar 7, 2011 at 21:49
  • no problem, luckily somebody found a solution to my problem. Thanks for trying!!!
    – MiKa
    Mar 8, 2011 at 12:08
4

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

2
  • is it possible to do this with tables we well? Oct 7, 2021 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 8, 2021 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.