1

i would like to do following, if i have a float and want to put in a picture, which is not as wide as the column. Then i want the caption to be left justified with the picture, like in following: enter image description here

but the caption gets left justified with the column if i use

\captionsetup{justification=raggedright,singlelinecheck=off}

with the caption package.

is it possible to get what i want?

2 Answers 2

0

Another solution relies on floatrow: the cation is justified between the natural width of the image.

\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} 

enter image description here

4

You could wrap image and caption in a minipage:

\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}

enter image description here


Alternative solution:

\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}
8
  • 1
    +1 But you are playing with the fire: if the OP accepts your nice answer, you will miss 66,666. ;-)
    – user121799
    Jun 19, 2018 at 19:21
  • @marmot Very true - I hope the OP understands the importance of palindromes :) Jun 19, 2018 at 19:23
  • yeah i had that idea already, but is it possible to make the width of the minipage automatic? and what is the problem with palindromes?
    – A.Ston
    Jun 19, 2018 at 19:25
  • @A.Ston The problem with palindromes is that if this would have answered your question and if you had accepted my answer, I would have gained 15 rep points and missed the palindrome :) For the automatic solution: I think I know an older answer - let me quickly search for it Jun 19, 2018 at 19:31
  • 1
    Oups, hope you don't mind that I pushed you over the 66,666. Congratulations, by the way ;-)
    – moewe
    Jun 19, 2018 at 19:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .