Table of Contents – Automatically Use List of Figure Entry in Caption

captionstable of contents

Using the optional argument for \caption it is possible to change the entry placed into a list of figures. The style I use in my thesis always has a "header" or "title" for a figure, i.e. a short part of the caption that I print in bold using textbf. This is in my case always the same as what I put into the optional argument of my captions:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}

\begin{document}
\listoffigures
\newpage
\begin{figure}[h!]
\centering
\includegraphics{example-image-a}
\caption[The universe]{\textbf{The Universe}\\Some very long description of this image that should not be in the list of figures...}
\label{fig:universe}
\end{figure}

\end{document}

Now I have The universe both as the entry in the list of figures and as a bold line at the beginning of the caption. Is there any way to achieve this automatically though? It often happens that I accidentally change only one or the other, e.g. ending up with

\caption[Something new]{\textbf{The Universe}\\Some very long description of this image that should not be in the list of figures...}

Where now Something new != The Universe

Best Answer

Define a new command \captionx

\newcommand{\captionx}[2]{\caption[#1]{\textbf{#1}\\ #2}}

to be used as

\captionx{Something new!}{Some very long description of this image that should not be in the list of figures...}

a

b

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}

\newcommand{\captionx}[2]{\caption[#1]{\textbf{#1}\\ #2}} % added <<<<<<<<<<<<<<<<

\begin{document}
    \listoffigures
    \newpage
    \begin{figure}[h!]
        \centering
        \includegraphics{example-image-a}
        \caption[The universe]{\textbf{The Universe}\\Some very long description of this image that should not be in the list of figures...}        
        \label{fig:universe}
    \end{figure}

    \begin{figure}[h!]
       \centering
       \includegraphics{example-image-b}
       \captionx{Something new!}{Some very long description of this image that should not be in the list of figures...} % <<<<<<<<<<<<<<
       \label{fig:new}
    \end{figure}
    
\end{document}