标题与图片左对齐

标题与图片左对齐

如果我有一个浮动元素,并且想放入一张图片,但图片的宽度不如列宽,那么我想这样做。然后我希望标题与图片左对齐,如下所示: 在此处输入图片描述

但如果我使用,标题会与列左对齐

\captionsetup{justification=raggedright,singlelinecheck=off}

带有标题包。

我可以得到我想要的吗?

答案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}

相关内容