[Tex/LaTex] Display short title and long title (both) in a caption

captionsformattingkoma-script

The syntax for a caption is

\caption[listoffigures/tables text]{Text actually displayed under picture/table}

But what I would like to have is something like this: If I use the above command, the text under the floating object should be

Label #.: listof text -- long text

With # being just the number and with -- being an arbitrary separator (either the -- dash itself or maybe even a \newline). Is this possible?

I'm using KOMAScript.

Best Answer

See the commented code. If you load any float-related packages (float, floatrow, caption, algorithmic, ...) or do things like \newfloat, \restylefloat etc., this my tweak must come after all that.

\documentclass{scrartcl}

\makeatletter
\let\x@caption\caption % original \caption
\def\x@@caption[#1]#2{\x@caption[{#1}]{#1 --- #2}} % with optional arg
\def\x@@@caption#1{\x@caption[{#1}]{#1}} % without optional arg
\def\caption{\@ifnextchar[\x@@caption\x@@@caption} % new \caption
\makeatother

\begin{document}

\listoffigures

\begin{figure}
\centering
\rule{5cm}{5cm}
\caption[Optional text.]{Obligatory text.}
\end{figure}

\begin{figure}
\centering
\rule{5cm}{5cm}
\caption{Obligatory text only.}
\end{figure}

\end{document}
Related Question