Graphics, Figures & TablesWrapping a figure within its own caption

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
pierre
Posts: 5
Joined: Fri Apr 02, 2010 3:28 pm

Wrapping a figure within its own caption

Post by pierre »

Hi all,

Sorry if this has been asked already but I didn't find anything really corresponding to my needs up until now. So here I go with my problem.

I need to have a figure wrapped within its own caption.

I know of the SCfigure package but if the caption exceeds the figure's height it stays squeezed. Basically, I would like something similar to what the wrapfigure environment proposes, but with the figure's caption, not external text.

Is it possible?
Thanks in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Wrapping a figure within its own caption

Post by sommerfee »

pierre wrote:Basically, I would like something similar to what the wrapfigure environment proposes, but with the figure's caption, not external text.
A \caption is no magic, it's just the text preceeded by \figurename~\thefigure and separated by a some symbols - usually :~

So you can easily typeset the caption by yourself to get the desired output, e.g.:

Code: Select all

\documentclass{article}
\newcommand\sample{Some text for our page
 that is reused over and over again. }

\usepackage{wrapfig}
\usepackage{caption}

\begin{document}
\listoffigures
\bigskip

\begin{wrapfigure}[3]{l}[0.2\width]{0pt}
  \centering
  \fbox{This is a ``wrapfigure''.}
\end{wrapfigure}
\captionlistentry[figure]{An example of the wrapfigure environment}
\figurename~\thefigure:
This is an example of the wrapfigure environment.
This is an example of the wrapfigure environment.
This is an example of the wrapfigure environment.
This is an example of the wrapfigure environment.
This is an example of the wrapfigure environment.
This is an example of the wrapfigure environment.
This is an example of the wrapfigure environment.
This is an example of the wrapfigure environment.

\sample \sample \sample
\end{document}
Note: I added the usage of the caption package to get an entry within the table of figures. If you don't need this, you can drop the usage of the caption package and replace \captionlistentry[figure]{...} with \refstepcounter{figure}.

HTH,
Axel
pierre
Posts: 5
Joined: Fri Apr 02, 2010 3:28 pm

Re: Wrapping a figure within its own caption

Post by pierre »

Hi Axel,

Thanks for the quick reply, this definitely helps. Didn't know how to make a wrapfigure look like I wanted, mainly because I always failed to make its wrapping text look like its caption.
Thanks a lot for your solution. :)
Post Reply