1

I would like to redefine the \caption command to have to arguments : one "main" caption and then the description.

This is what I want :

 \begin{figure}
 \caption{\textbf{Caption title} \newline \small{I would like this sentence to be under the title and smaller.}}
 \end{figure}

Figure 1 - Caption title

I would like this sentence to be under the title and smaller.


But I want to change the format for all captions. I looked at the package caption :

\documentclass[10pt]{article}
\usepackage[french,english]{babel}
\usepackage[utf8]{inputenc}  
\usepackage[margin=10pt,font=small,labelfont=bf,
           labelsep=endash]{caption}

\newlength\myindention
\DeclareCaptionFormat{myformat}%
               {#1#2\\\hspace*{\myindention}#3}
\setlength\myindention{1cm}
\captionsetup{format=myformat}


\begin{document}

 \begin{figure}
 \caption{Caption title. I would like this sentence to be under the title and smaller.}
 \end{figure}


 \end{document}

Figure 1

 Caption title. I would like this sentence to be under the title and smaller.

But only the title is above (which I expected, because I gave no indication about it - but I don't know how to change it).

I tried to add arguments in the formatting command :

    \DeclareCaptionFormat{myformat}%
               {#1#2#3 \newline \small{#4}}

    ...
         \caption{Caption title.}{I would like this sentence to be under the title and smaller}

But I get : "Illegal parameter number in definition of \caption"

Any help on that ?

4
  • \newcommand\mycaption[2]{\caption{\textbf{#1}\newline\small#2}}? Commented May 30, 2016 at 8:31
  • Ow. It is my first time using \newcommand and I had missed the [2]. I did not think it was that simple. Thanks, it works perfectly.
    – Nausi
    Commented May 30, 2016 at 8:50
  • a question for you ... do you want the full description in the table of contents? if not, there is nothing to prevent you from placing a block of text, separate from the caption, into a figure (or other float) environment. Commented May 30, 2016 at 16:22
  • True, I definitely don't want all the description in the ToC. I admit I had not thought about juste writing some text, which seems indeed to be the simplest solution...
    – Nausi
    Commented May 31, 2016 at 7:15

1 Answer 1

2

Instead of manipulation the original \caption command it might be easier to define a new command which handles the two arguments as intended.

\documentclass{article}
\newcommand\mycaption[2]{\caption{\textbf{#1}\newline\small#2}}
\begin{document}
\begin{figure}
  \mycaption{Caption title}{I would like this sentence to be under the title and smaller.}
\end{figure}
\end{document}

enter image description here

You must log in to answer this question.

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