# Align figure to the right (with \raggedleft) while still centering its caption with respect to the image

I am wondering if it is possible to align an image to the right margin of the page (with \raggedleft) while still having it's caption nicely centered (with \centering) under the image (centered with respect to the image itself I mean, not w.r.t the page).

Is this possible in latex? Ideally the solution should work within both a figureand wrapfigure environments.

-
The standard LaTeX document classes are all set to center a "short" caption (i.e., a caption that fits on a single line) irrespective of what you do with the rest of the floating environment's contents. –  Mico Apr 9 '12 at 17:03
Maybe I should have specified that I use the caption package: \usepackage[margin=10pt,font=small,labelfont=bf,justification=centering,belowsk‌​ip=0pt]{caption} –  Matthias Apr 9 '12 at 17:04
In that case you should be all set for figure floats: the captions will be set centered regardless of whether you use \centering, \raggedleft, or whatnot for the rest of the figure environment. Not sure if this is also true for wrapfigure environments -- it may depend on how large the indented graphic is relative to the \linewidth parameter. Not knowing how these parameters are set in your code, I can't be more specific. –  Mico Apr 9 '12 at 17:15
@Mico: Thanks for your input. I will look into it ASAP :). If it does not solve my problem I will provide a MWE to bring some clarity. –  Matthias Apr 14 '12 at 12:46
I have a feeling that @GonzaloMedina's answer is better than mine; I may not have understood correctly that you need the caption to be centered on (and no wider than) the right-justified float. –  Mico Apr 14 '12 at 14:58

If I understood your question correctly, you can simply use a minipage:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage[margin=10pt,font=small,labelfont=bf,justification=centering]{caption}
\usepackage{lipsum}

\begin{document}

\lipsum[2]
\begin{figure}
\raggedleft
\begin{minipage}{5cm}
\includegraphics[width=5cm]{name}
\caption{Some caption that spans more than a line and some additional text}
\end{minipage}
\end{figure}

\end{document}


-
How to decrease the space between figure and the figure caption. after insert the ps figure and its figure caption, both seem to far apart. –  sonu May 9 '13 at 14:32