![与图形标签对齐的文本](https://linux22.com/image/475083/%E4%B8%8E%E5%9B%BE%E5%BD%A2%E6%A0%87%E7%AD%BE%E5%AF%B9%E9%BD%90%E7%9A%84%E6%96%87%E6%9C%AC.png)
答案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}