3

I would like to have two captions for some tables and figures, where the first caption describes the general content and the second caption provides some additional information.

The idea is to have the second caption left-aligned with the caption text of the first caption rather than with the caption label, that is, left-aligned with the description of the contents of the table (figure) rather than with the word Table (Figure).

I thought the option [format=hang,indention=0cm] from the caption package would achieve that but the second caption appears centered. I would have thought that the second caption would be treated as a second paragraph in the caption but clearly I'm wrong (see Table 1).

I found a similar query in this site (see here), hence I modified a bit the code in the suggested answer. For short captions it works well (see Table 2), but for long captions, the second caption is not aligned with the first (see Table 3). I realise that my code probably is far from efficient and hence it is introducing some bugs, so any help will be greatly appreciated.

enter image description here

\documentclass{article}
\usepackage[format=hang,indention=0cm]{caption}

% some auxiliary lengths for aligning the captions
\newlength\mylena
\newlength\mylenb
\newlength\mylenc

% new command: \MyCaption{First numbered caption}{Second unnumbered caption}
\newcommand\MyCaption[2]{%
    \captionsetup{belowskip=-\baselineskip}
    \settowidth\mylena{\tablename~\thetable:~ #1}
    \settowidth\mylenb{\small{#2}}
    \settowidth\mylenc{\tablename~\thetable:~}
    \caption{#1}
    \caption*{\hspace*{\dimexpr%
        \mylenb - \mylena + \mylenc + \mylenc \relax} 
        \small{#2}}
    \setlength\belowcaptionskip{\baselineskip}
}

\begin{document}

\begin{table}[ht]
    \caption[LoT entry]{The first caption 

    (The second caption)}
     \centerline{
        \begin{tabular}{lrr}
        \hline
         & C1  & C2 \\
        \hline
        R1 & & \\
        R2 & & \\
        \hline
        \end{tabular}
        }
\end{table}

\begin{table}[ht]
    \MyCaption{The first caption}{(The second caption)}
     \centerline{
        \begin{tabular}{lrr}
        \hline
         & C1  & C2 \\
        \hline
        R1 & & \\
        R2 & & \\
        \hline
        \end{tabular}
        }
\end{table}

\begin{table}[ht]
    \MyCaption{A long first caption A long first caption A long first caption A long first caption A long first caption }{(A long second caption A long second caption A long second caption A long second caption A long second caption )}
     \centerline{
        \begin{tabular}{lrr}
        \hline
         & C1  & C2 \\
        \hline
        R1 & & \\
        R2 & & \\
        \hline
        \end{tabular}
        }
\end{table}

\end{document}
2

It's easier if you omit the code that tests for a short caption and centres it and forces it to always use the paragraph setting. nooneline option.

enter image description here

\documentclass{article}
\usepackage[format=hang,indention=0cm,nooneline]{caption}

% some auxiliary lengths for aligning the captions
\newlength\mylena
\newlength\mylenb
\newlength\mylenc
\makeatletter
% new command: \MyCaption{First numbered caption}{Second unnumbered caption}
\newcommand\MyCaption[2]{%
    \caption[#1]{#1\par\small#2\par}%
}

\begin{document}


\begin{table}[htp]
    \MyCaption{The first caption}{(The second caption)}
     \centerline{
        \begin{tabular}{lrr}
        \hline
         & C1  & C2 \\
        \hline
        R1 & & \\
        R2 & & \\
        \hline
        \end{tabular}
        }
\end{table}

\begin{table}[htp]
    \MyCaption{A long first caption A long first caption A long first caption A long first caption A long first caption }{(A long second caption A long second caption A long second caption A long second caption A long second caption )}
     \centerline{
        \begin{tabular}{lrr}
        \hline
         & C1  & C2 \\
        \hline
        R1 & & \\
        R2 & & \\
        \hline
        \end{tabular}
        }
\end{table}

\end{document}
  • Thank you David. However now the entire caption is left-aligned. Any suggestion to keep it as in the original Table 2? – Jhon MC Sep 18 '13 at 15:56
  • @JhonMC well it doesn't change the alignment at all really, the requirement to hang indent the second paragraph the same way as the first only really makes sense if the first is set as a paragraph. The standard behaviour is to first try to set it as one centred line and if it fits do that, so the first short text was being set in an hbox. If the first caption is short but the second is long, this layout is probably still OK. Just if as above they are both short then the "natural" thing to do would be to center each, but that is exactly what you commented about in the question:-) – David Carlisle Sep 18 '13 at 16:29
  • thank you for the clarification. Indeed, your code is making the caption package recognize each of the two captions as paragraphs (which I didn’t know how to do) but is not addressing the issue of the placement of the captions. Well, I still need to a bit of work in order to improve that. Cheers. – Jhon MC Sep 18 '13 at 23:32

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.