6

I'm trying to get a caption to span the figure width on a wrapfig environment. But for some reasons it just won't go. Here is my code and a graphical representation:

problem

\begin{wrapfigure}{R}{0.3\textwidth}    
  \vspace{-30pt}
  \label{fig:UbiContentClass}
  \ffigbox[\textwidth]
  {
    \caption{A classe que define Conteúdo Ubíquo}
  }
  {
    \includegraphics[width=\textwidth]{figs/UbiContentClass.png}
  }
  \vspace{-20pt}
\end{wrapfigure}
  • 3
    Please add to your question a complete and minimal version of the code illustrating the problem. – Gonzalo Medina Apr 13 '12 at 02:48
  • ...this will just make things easier for others to help you. Change your \includegraphics[width=\textwidth]{...} into \rule{\textwidth}{...} and include at least floatrow and wrapfig. Don't use the minimal document class, but article rather. – Werner Apr 13 '12 at 02:50
  • @Werner I don't get it - you're saying to replace 'includegraphics' with 'rule'? I tried this but it doesn't build: \documentclass{article} \usepackage{floatrow} \usepackage{graphicx} \usepackage{wrapfig}

    \begin{document}

    \begin{figure} \ffigbox[\FBwidth] { \caption{caption text caption text caption text caption text caption text caption text caption text caption text caption text caption text caption text caption text }\label{...} } { %\includegraphics[width=.4\linewidth]{dummy} \rule{.4\linewidth]{dummy} } \end{figure}

    \end{document}

    – David Doria Feb 03 '14 at 18:05
  • @DavidDoria: The motivation is that we don't have the OP's figs/UbiContentClass.png. An alternative would be to use image from the mwe package so that everyone can replicate the problem without having to worry about missing images. \rule{<width>}{<height>} is how you should use it to create a black box of width <width> and height <height>. If you \usepackage[demo]{graphicx}, then all images will appear in 100mmx150mm black boxes, but that may not be the size of the original graphic. – Werner Feb 04 '14 at 16:59

1 Answers1

5

Use \ffigbox[\FBwidth] instead of \ffigbox[\textwidth]. This will equal the caption width to that of object. Here is a screen shot from floatrow documentation for more details.

enter image description here

The MWE for your case:

\documentclass{article}
\usepackage[demo]{graphicx} % Remove demo in your file
\usepackage{wrapfig,floatrow}
\usepackage{lipsum} % provides dummy text
%------------------------------------------
\begin{document}
\lipsum[1-2]
\begin{wrapfigure}{R}{0.3\textwidth}
%\vspace{-30pt} % why this space?
  \label{fig:UbiContentClass}
  \ffigbox[\FBwidth]
  {
    \caption{A classe que define Conteúdo Ubíquo}
  }
  {
    \includegraphics[width=\textwidth]{figs/UbiContentClass.png}
  }
%\vspace{-20pt} % why this space?
\end{wrapfigure}
\lipsum[2-3]    
%------------------------------------------
\end{document}

enter image description here

  • The space is to remove the extra empty stuff. – Marcos Roriz Junior Apr 13 '12 at 16:56
  • @Harish Kumar I tried this (without the wrapfigure) and it lets the caption be much wider than the image: \documentclass{article} \usepackage{floatrow} \usepackage{graphicx} \usepackage{wrapfig}

    \begin{document}

    \begin{figure} \ffigbox[\FBwidth] { \caption{caption text caption text caption text caption text caption text caption text caption text caption text caption text caption text caption text caption text }\label{...} } { \includegraphics[width=.4\linewidth]{dummy} } \end{figure}

    \end{document}

    – David Doria Feb 03 '14 at 18:06
  • @DavidDoria You have to use \includegraphics[width=\linewidth]{example-image-a}. note \linewidth instead of 0.4\linewidth. –  Feb 03 '14 at 22:52
  • @HarishKumar but then the image is also linewidth. I want to size my image to my liking, then have the text aligned to its edges below it. – David Doria Feb 04 '14 at 12:42
  • @DavidDoria If you use 0.4\linewidth natually image will be smaller as the caption will span \linewidth. –  Feb 04 '14 at 23:37
  • @HarishKumar So that is the question - how to get the caption to span only the figure width, whatever it may be? – David Doria Feb 05 '14 at 14:39
  • @DavidDoria Change \ffigbox[0.2\FBwidth]. Change accordingly. –  Feb 06 '14 at 00:14
  • @HarishKumar I don't understand what this is doing. According to the floatrow doc, "But if you set, for example, the option [\FBwidth] like below, you’ll get a caption width equal to the width of picture". With \ffigbox[\FBwidth] and \includegraphics[width=.5\linewidth]{dummy}, the caption is much bigger than the figure. If I make it \ffigbox[.5\FBwidth] to match, then the figure gets even smaller, and the caption is still bigger than the figure. What is the relationship between these two width settings? – David Doria Feb 06 '14 at 13:05
  • @DavidDoria \FBwidth equals the natural width of the float contents. ie, here \begin{wrapfigure}{R}{0.3\textwidth}. But includegraphics has a width of .4\linewidth, ie, 0.4 times the width of 0.3\textwidth. For details on line width and \textwidth see Difference between \textwidth, \linewidth and \hsize. –  Feb 06 '14 at 22:52
  • @HarishKumar I'm sorry, so I still don't understand then how I would make the caption the same width as the figure? – David Doria Feb 10 '14 at 12:51