Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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
1  
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

1 Answer 1

up vote 5 down vote accepted

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}

enter image description here

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.