答案1
好消息是会singlelinecheck
自动计算标题的宽度。但是,根据选项的不同,计算位置可能有所不同。
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx, caption,lipsum}
\newcommand{\mycaption}[3][\empty]{% #1=short caption (optionsl), #2=caption, #3=text
\ifx\empty#1\relax
\caption[#1]{#2}%
\else
\caption[#1]{#2}
\fi
\sbox0{\figurename~\thefigure:}% compute width of line
\sbox1{\usebox0 #2}% compute width of centered text
\ifdim\wd1>\linewidth \wd1=\linewidth \fi% perform single line check
\parbox{\wd1}{\raggedright\footnotesize
\leavevmode\rlap{\raisebox{\ht\strutbox}{\rule{\wd0}{0.5pt}}}%
#3}\par}
\begin{document}
\lipsum[1-1]
\begin{figure}[ht]% to avoid large blank spaces
\centering
\includegraphics[width=3cm]{example-image}
\mycaption{Some sort of image}{Source: Image black book}
\end{figure}
\lipsum[2-2]
\end{document}