2

I have a problem about positioning of the caption. My code of the figure is like this:

\usepackage[format=hang]{caption}

\begin{figure}[!h]
\centering
\captionsetup{justification=raggedright,singlelinecheck=false}

\captionbox{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.}{

   \fbox{\includegraphics[width=4in]{basicLDPC}}}
   \label{fig:dummy}

\end{figure}

The output is :

The simple output

The problem is the caption must be at above of the figure. How can I do that?

Edited

Is there any possible way to add a text after the figure like a footnote to write the source of it?

Thanks

2
  • Where does that \captionbox come from? And please do not post code snippets. Commented Jun 22, 2015 at 11:27
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – LaRiFaRi
    Commented Jun 22, 2015 at 11:34

1 Answer 1

6

Just set the option figureposition=top:

% arara: pdflatex

\documentclass{article}
\usepackage[demo]{graphicx} % remove that option
\usepackage{caption}
\captionsetup{%
    ,format=hang
    ,justification=raggedright
    ,singlelinecheck=false
    ,figureposition=top
    }

\begin{document}
\begin{figure}[!h]
    \centering
    \captionbox{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.\label{fig:dummy}}{%       
        \fbox{\includegraphics[width=4in]{basicLDPC}}}
\end{figure}
\end{document}

enter image description here


Off-topic: Please note the % in the 4th last line which was missing.

2
  • Nice answer, but for the \label to work I think it needs to be inside captionbox.
    – Davi
    Commented Jul 11, 2021 at 18:47
  • @Davi thanks for the pointer
    – LaRiFaRi
    Commented Aug 4, 2021 at 7:58

You must log in to answer this question.

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