7

I have a problem with the alignment of the caption of an image. My image is centered and I need the caption to be left-adjusted relative to my image like that:

                    -------------------
                    |                 |          
                    |      image      |
                    -------------------
                    Figure 1: my image
                    Source:              

I tried the caption package with:

\captionsetup{font=footnotesize, justification=raggedright,singlelinecheck=false}

Code to load figure:

\begin{figure}[htpb]
  \centering
  \includegraphics[width = 10cm]{Zeichnungsverfahren.png}  
  \caption[caption]{This is the caption}  
  \label{fig:zeichnungsverfahren2}
\end{figure}

but it clearly didn't work.

It gave me something like this:

                    -------------------
                    |                 |          
                    |      image      |
                    -------------------
Figure 1: my image

Source:   

I'm new with Latex so I hope you can help me out.? Greets Tony

2 Answers 2

2

There is a yet not documented macro called \captionbox in the caption package which should do what you want.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{caption}

\captionsetup{
  font=footnotesize,
  justification=raggedright,
  singlelinecheck=false
}

\begin{document}
  \begin{figure}[!htb]
    \centering
    \captionbox{Caption\label{fig:dummy}}{%
      \rule{8cm}{4.5cm}
    }
  \end{figure}
\end{document}

The syntax of this command is identical to \subcaptionbox, which is described in Section 4 of the subcaption manual.

Note that the caption will now no longer exceed the width of the object at both sides.


enter image description here


Update

According to the comment this is an example with a new line for the source of the figure.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{caption}

\captionsetup{
  font=footnotesize,
  justification=raggedright,
  singlelinecheck=false
}

\begin{document}
  \begin{figure}[!htb]
    \centering
    \captionbox[Caption]{Caption\par Source:\label{fig:dummy}}{%
      \rule{8cm}{4.5cm}
    }
  \end{figure}
\end{document}

enter image description here

5
  • 1
    By the way, the »floatrow« package offers a similar command. Sep 4, 2013 at 13:23
  • Thank you very much for your quick answer! Your code does not compile in with my system. "Undefined Control Sequence" in the line with "\captionbox.." . Could it be that I have a version of the caption package which is too old?
    – Tony
    Sep 4, 2013 at 13:27
  • @Tony: Make sure that your version of »caption« is up to date. Current version is v3.3-89 from 2013/05/02. Do an update of your TeX system. Sep 4, 2013 at 13:30
  • Thank you very much! I updated texlive and your code works now wonderfully! There is one other little thing, I hope it is ok when I write it right here. I need another line in the caption, I updated it above in my example. I found this tex.stackexchange.com/questions/101595/… but it didn't work.
    – Tony
    Sep 4, 2013 at 14:40
  • @Tony: See the update. Sep 4, 2013 at 15:01
0

If anyone needs the same anytime, the following code should solve.

\begin{figure}[htpb]
   \centering
    \captionbox[Text]{Zehcninasddwqe \label{fig:dummy}\subcaption*{Source: www...}}{%
     \includegraphics[width = 10cm]{zeichnen.png}  
    }   
 \end{figure}

You must log in to answer this question.

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