1

I just wrote a long 200 pages documents with Latex, and realized a small issue. All my figure have the following format:

\documentclass[a4paper,11pt,fleqn]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french,german,english]{babel}
\usepackage{graphicx}

\begin{document}

\begin{figure}[!ht]
  \centering
    \includegraphics[width=0.9\textwidth]{image.pdf}
 \caption[Short Description]{Long Description}
  \label{fig:test}
\end{figure}

\end{document}

The caption of this figure reads as "Figure 1.1 - Long Description".

And the short description is only shown in my list of figures. Is there a way to automatically add the short description at the beginning of the long description, in bold? Such that I don't need to edit all the figures manually?

So it would read as: "Figure 1.1 - Short Description. Long Description".

Or do I need to manually go through all my figures and edit them like this?:

\begin{figure}[!ht]
  \centering
    \includegraphics[width=\textwidth]{my_figure.pdf}
 \caption[Short description.]{\textbf{Short description.} Long description}
  \label{fig:my_label}
\end{figure}

I tried using this macro, but it doesn't work:

\renewcommand{\caption}[2]{\caption[#1]{\textbf{#1}. #2}}

Thank you in advance for your help!

4
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Nov 27, 2018 at 12:26
  • You never have to repeat something 150 times. When you are facing such a problem, you have to introduce macros. But to help us answer, please enlarge your MWE to make it fully compiliable : add a preamble with all the packages you are using to compile this peculiar small example.
    – sztruks
    Nov 28, 2018 at 8:05
  • Thanks for the response. I didn't know about macros, I read about them and tried to use them but it doesn't work. I edited my question above with a MWE. Nov 29, 2018 at 13:04
  • Ok I found the solution (see below). Not sure why I need to put empty brackets but it works out. One of the mistakes i made was the infinite nesting because I was reusing caption in the new caption command... Thanks again. Nov 29, 2018 at 13:32

1 Answer 1

1

I found the solution, by reading a bit more in details about macros:

\let\oldcaption\caption
\renewcommand\caption[2][]{\oldcaption[#1]{\textbf{#1.} #2}}

I understood everything except why I need the empty brackets [].

I would had expected the command below to work, but it doesn't:

\let\oldcaption\caption
\renewcommand{\caption}[2]{\oldcaption[#1]{\textbf{#1.} #2}}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .