0

I have used the following approach to automatically make the first sentence of a float caption bold (in combination with hyperref): Hyperref compatability with automatically bolded first sentence of float caption float.

However, additionally I also need to have a short version of the caption in my list of figures / list of tables (as most of my captions are very long). The usual way with \caption[entry in LOF]{full caption} does not work anymore. Is there a possibility to automatically depict the bold part of the caption in the LOF/LOT?

\documentclass{scrbook}
\usepackage{caption}
\usepackage{xstring}
\usepackage{hyperref}

\makeatletter
\newcommand\formatlabel[1]{%
    \noexpandarg
    \IfSubStr{#1}{.}{%
      \StrBefore{#1}{.}[\firstcaption]%
      \StrBehind{#1}{.}[\secondcaption]%
      \textbf{\firstcaption.} \secondcaption}{%
      #1}%
}
\AtBeginDocument{%
  \newcommand*{\org@caption}{}%
  \let\org@caption\@caption
  \def\@caption#1[#2]#3{%  
    \org@caption{#1}[{#2}]{\formatlabel{#3}}%
  }%
}   
\makeatother

\begin{document}

\begin{figure}[tb]
  \caption{First sentence is bold. Second sentence is not.}
  \label{fig:figure1}
\end{figure}

\end{document}
2

I adapted this post to set the bold part as short description.

\documentclass{scrbook}
\usepackage{caption}
\usepackage{xstring}
\usepackage{hyperref}

\makeatletter
\def\getfirst#1.#2\relax{{#1}}
\def\getsecond#1.#2\relax{{#2}}

\AtBeginDocument{%
    \newcommand*{\org@caption}{}%
    \let\org@caption\@caption
    \def\@caption#1[#2]#3{%  
        \org@caption{#1}[\getfirst#3\relax]{{\bfseries\getfirst#3\relax} \getsecond#3\relax}%
    }%
} 

\makeatother

\begin{document}

    \begin{figure}[tb]
        \caption{First sentence is bold. Second sentence is not.}
        \label{fig:figure1}
    \end{figure}
    \listoffigures
\end{document}

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.