答案1
另一种解决方案依赖于floatrow
:阳离子在图像的自然宽度之间是合理的。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{ebgaramond}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{floatrow}
\captionsetup{justification=raggedright,singlelinecheck=off}
\usepackage{lipsum}
\begin{document}
\begin{figure}[! htbp]
\centering
\begin{floatrow}
\ffigbox[\FBwidth]{ \caption{Lewis Carroll}}{\includegraphics[scale=0.1]{Charles-Dodgson}}
\end{floatrow}
\end{figure}
There was a table set out under a tree in front of the house, and the
March Hare and the Hatter were having tea at it: a Dormouse was sitting
between them, fast asleep, and the other two were using it as a
cushion, resting their elbows on it, and talking over its head. ‘Very
uncomfortable for the Dormouse,’ thought Alice; ‘only, as it’s asleep, I
suppose it doesn’t mind.’
The table was a large one, but the three were all crowded together at
one corner of it: ‘No room! No room!’ they cried out when they saw Alice
coming. ‘There’s PLENTY of room!’ said Alice indignantly, and she sat
down in a large arm-chair at one end of the table.
\end{document}
答案2
您可以将图像和标题包装在小页面中:
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=off}
\usepackage{lipsum}
\begin{document}
\lipsum[2]
%
\begin{figure}[htbp]
\centering
\begin{minipage}{.7\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{test}
\end{minipage}
\end{figure}
\lipsum[2]
\end{document}
替代解决方案:
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=off}
\usepackage{lipsum}
\newlength{\imagewidth}
\begin{document}
\lipsum[2]
%
\begin{figure}[htbp]
\centering
\setlength{\imagewidth}{.7\textwidth}
\includegraphics[width=\imagewidth]{example-image}
\captionsetup{width=\imagewidth}
\caption{test}
\end{figure}
\lipsum[2]
\end{document}