[Tex/LaTex] Automatically bold first sentence of a floats caption

boldcaptionsformatting

How to bold automatically the first sentence of the float caption and second sentence is normal?

\begin{figure}[t]
\centering
\caption{First sentence. Second sentence.}
\end{figure}

Output should be:

Figure 1. First sentence. Second sentence.

Best Answer

You can use the approach described in Customize text format of captions by parsing content of \@caption, namelly

\documentclass{article}
\usepackage{xstring}
\usepackage{etoolbox}
\usepackage{caption}

\captionsetup{labelfont=bf,tableposition=top}

\makeatletter
\newcommand\formatlabel[1]{%
    \noexpandarg
    \IfSubStr{#1}{.}{%
      \StrBefore{#1}{.}[\firstcaption]%
      \StrBehind{#1}{.}[\secondcaption]%
      \textbf{\firstcaption.} \secondcaption}{%
      #1}%
      }


\patchcmd{\@caption}{#3}{\formatlabel{#3}}
\makeatother

\begin{document}

\begin{figure}[t]
\centering
test test
\caption{First sentence. Second sentence.}
\end{figure}

\end{document}
Related Question