1

This is an add-on to another question.

Same usecase: "make \caption to print both short and long captions for a float, where short caption uses boldface"

Solution by Teepeemm was

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

and it works perfectly.

But I also use the subcaption package and it breaks it for some reason. Any fixes?

MWE (or minimum not working example):

\documentclass{scrreprt}
\usepackage{subcaption}

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

\begin{document}

\begin{figure} \centering \rule{5cm}{1cm} \caption[This is a figure]{This is the more detailed description of the figure} \end{figure}

\begin{table} \centering \rule{5cm}{1cm} \caption[This is a table]{This is the more detailed description of the table} \end{table}

\end{document}


Edit: Added the complete solution from the previous question

  • Can't you simply use: \caption[\bfseries This is a table]{This is the more detailed description of the table}? Then you do not need to redefine the \caption command. – user187802 Aug 22 '22 at 18:12
  • It makes a difference where \let\oldcaption=\caption is placed. You could use \makeatletter \let\oldcaption=\caption@caption \makeatother to make sure you are using the caption package caption. – John Kormylo Aug 22 '22 at 23:34
  • @JohnKormylo That doesn't seem to work. Just tried it in several variations. Also, shouldn't it work anyways, if \let\oldcaption=\caption is placed after \usepackage{subcpation} as \caption has already be redefined at that point? – PaulMndn Aug 23 '22 at 08:49
  • Unless you are using something like KOMA, which redefines \caption at the beginning of each figure or table. – John Kormylo Aug 23 '22 at 13:17
  • @JohnKormylo Well, I do use KOMA (scrreprt), but if I comment out \usepackage{subcaption} it still works, so it must have something to do with subcaption (or caption as my tests suggest which is included in subcaption) – PaulMndn Aug 23 '22 at 15:52
  • The simple answer is that KOMA is not compativle with subcaption. However, see https://tex.stackexchange.com/questions/22177/can-the-package-caption-be-used-with-komascript-classes/383025?r=SearchResults&s=2%7C32.3076#383025 (which was presumably down voted by a KOMA purist, even though it works). – John Kormylo Aug 23 '22 at 19:57

0 Answers0