# Wrapping text around multiple figures

I am a beginner in LaTex, but I have to to do this in a hurry:

I need to write a macro to handle 2 cases (or one macro for both).

1st case: i have 1 - 3 pictures on the right side, and the left text should "flow" around it.

2nd case (nasty one :( ): i have 1 - 6 pictures and text should do the same.

My problem is this : how to layout pictures in page because pictures should be "anchored" to some paragraph (for example 1st picture to paragraph 1, 2nd picture to paragraph 4, 3rd to paragraph 5). I have to write a macro to handle such cases.

Can anyone help me or direct me to the right web instructions, plz ?

-

## migrated from stackoverflow.comJul 16 '11 at 11:36

This question came from our site for professional and enthusiast programmers.

Have you tried combining wrapfig with a nested subfig? – SiggyF Jul 16 '11 at 9:01
Welcome to TeX.sx! Your question was migrated here from another stackexchange site. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. Also I agree that wrapfig seems to be the way to go. – Martin Scharrer Jul 16 '11 at 11:45
@DiggyF: I think subfig doesn't work outside normal floats. – Martin Scharrer Jul 16 '11 at 11:54
So fast reply. I will try that. Thank you all. Bob – user6737 Jul 16 '11 at 12:32
Please don't use answer posts for comments. You need to connect your two accounts from stackoverflow.com and this partner site together. Then you own the question again and can comment to all answers. Commenting everywhere requires 50rep points. – Martin Scharrer Jul 16 '11 at 14:25

This reading shows you something you may be interested in. The wrapfig package altogether with the subfig are a good suggestions, though you need to put your wrapfigure env before the first paragraph of the page and you must know and "fix" the width of the content, something like

\documentclass{article}
%\usepackage{subfig}
\usepackage{wrapfig}

\begin{document}
\begin{wrapfigure}{r}{.6\textwidth}
%% your content, maybe with \subfloats
\end{wrapfigure}

% the very first text of the "new" page
Lorem ipsum dolor sit amet...

...
\end{document}


The link shows you the example of the gull, where the width of the graphics is a little bit less than the width passed to wrapfig.

The idea behind floating insertions is to free authors from thinking too much about where things go. Usually, you should not be worried about it, unless you are doing something that it is out of the "scope" of (La)TeX, though of course you can do it e.g. writing your own package and playing with LaTeX internals or TeX primitives, or hoping someone else had your same "problem" and wrote something to solve it...

In particular your rightmost second case can't be done with subfigs and wrapfig (or at least, I was not able to do it using these packages).

Reading manuals of the packages may help too (the direct link is to it mirror of ctan, likely you would prefer a different mirror)

-

As already mentioned by others this can be done using the wrapfig package. You need to place the wrapfigure just before the paragraph. See the example code below. However, it only supports rectangular figures. You will need to use two of them for the last example but need to place at least one paragraph between them, which makes it a little tricky. If you need captions for the images use the caption of capt-of package which both provide the macro \captionof{figure}{<your caption>}. The subfig package is normally used if you want sub-figures with (a), (b), etc. sub-captions, but I think it doesn't work outside a normal float.

\documentclass{article}
\usepackage{wrapfig}

\usepackage{xcolor}
\usepackage{lipsum}% dummy text only

\begin{document}

\lipsum[1]

\begin{wrapfigure}{r}{3cm}
\begin{tabular}{@labe{}c@{}}
\textcolor{blue}{\rule{3cm}{3cm}} \\% Dummy image replacement
\textcolor{green}{\rule{3cm}{3cm}} \\% Dummy image replacement
\textcolor{red}{\rule{3cm}{3cm}} \\% Dummy image replacement
\end{tabular}
\end{wrapfigure}

\lipsum[2-4]

\newpage

\lipsum[1]

\begin{wrapfigure}{r}{3cm}
\begin{tabular}{@{}c@{}}
\textcolor{blue}{\rule{3cm}{3cm}} \\% Dummy image replacement
\textcolor{green}{\rule{3cm}{3cm}} \\% Dummy image replacement
\end{tabular}
\end{wrapfigure}

\lipsum[2-4]

\newpage

\lipsum[1]

\begin{wrapfigure}{r}{3cm}
\begin{tabular}{@{}c@{}}
\textcolor{blue}{\rule{3cm}{3cm}} \\% Dummy image replacement
\end{tabular}
\end{wrapfigure}

\lipsum[2-3]

\newpage

\lipsum[1]

\begin{wrapfigure}{r}{6.5cm}
\begin{tabular}{@{}cc@{}}
\textcolor{blue}{\rule{3cm}{3cm}} &% Dummy image replacement
\textcolor{orange}{\rule{3cm}{3cm}} \\% Dummy image replacement
\textcolor{green}{\rule{3cm}{3cm}} &% Dummy image replacement
\textcolor{yellow}{\rule{3cm}{3cm}} \\% Dummy image replacement
\textcolor{red}{\rule{3cm}{3cm}} &% Dummy image replacement
\textcolor{brown}{\rule{3cm}{3cm}} \\% Dummy image replacement
\end{tabular}
\end{wrapfigure}

\lipsum[2-3]

\newpage

\lipsum[1]

\begin{wrapfigure}{r}{6.5cm}
\begin{tabular}{@{}cc@{}}
\textcolor{blue}{\rule{3cm}{3cm}} &% Dummy image replacement
\textcolor{green}{\rule{3cm}{3cm}} \\% Dummy image replacement
\end{tabular}
\end{wrapfigure}

\lipsum[2]
\begin{wrapfigure}{r}{3cm}
\begin{tabular}{@{}c@{}}
\textcolor{red}{\rule{3cm}{3cm}} \\% Dummy image replacement
\end{tabular}
\end{wrapfigure}

\lipsum[3]

\newpage

\end{document}


-