# wrapfigure and fbox with floatrow

I am new to latex and still in the stage where I am modifying example code, so maybe there is a better way to do this or I'm just missing something. I have 3 subfigures and I want them to stack in a nice little column with the text wrapped around them. I'd also like to put a box around the whole thing. I'm using floatrow for all my other graphics (so far).

wrapfigure and floatrow work fine in my single-line images, but when I tried using subfloatrow to stack the images, I get strange behavior. It depends on whether I have text before and/or after the wrapfigure, but here is an example:

I don't need it exactly after that paragraph, I'd just like it somewhere nearby. So ideally in this case I would have wanted wrapfigure to scooch it up, in addition to properly shifting it leftward into that hole it made.

Separately, I've been using fbox to put a box around my groups of figures, but if I try that here it puts them back in a horizontal row.

How do I do these two things? Wrap text around stacked subfigures, and put a box around it.

\documentclass[11pt]{amsart}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{floatrow}
\DeclareFloatVCode{largevskip}
{\vskip 20pt}
\captionsetup[figure]{font=small}
\usepackage{subfig}
\usepackage{wrapfig}

\usepackage{lipsum}

\begin{document}

\lipsum[1-2]

\begin{wrapfigure}{r}{0.4\textwidth}
%\begin{figure}
\ffigbox[\FBwidth]
%    {\setlength\fboxsep{4pt} \fbox
{\begin{subfloatrow}
\ffigbox[\FBwidth]
{\includegraphics[width=\textwidth]{example-image-a}}
{\caption{Subcaption 1}\label{sfig:ex1}}
\end{subfloatrow}

\begin{subfloatrow}
\ffigbox[\FBwidth]
{\includegraphics[width=\textwidth]{example-image-a}}
{\caption{Subcaption 2}\label{sfig:ex2}}
\end{subfloatrow}

\begin{subfloatrow}
\ffigbox[\FBwidth]
{\includegraphics[width=\textwidth]{example-image-a}}
{\caption{Subcaption 3}\label{sfig:ex3}}
\end{subfloatrow}}
%    }
{\caption{asdf!} \label{fig:ex}}
\end{wrapfigure}
%\end{figure}

\lipsum[3-4]

\end{document}

• The whole point of floatrow is to align images and captions side by side. In this case it serves no useful function whatsoever. Second, your main problem is that the combined images are too large to fit on the page, and wrapfig doesn't break. – John Kormylo Nov 11 '17 at 14:23
• Right, I suspected the floatrow wasn't necessary, but I wasn't sure what other packages it interfered with, and I figured it should still be doable. The images aren't actually too large, I just didn't screencapture the top of the page- I was afraid it'd be a giant image, but now that I think about it, that's not a big deal... – Irene Nov 11 '17 at 20:24

I suggest to take a look at this first: Handling of wrapfig pictures in LaTeX

As you will notice, sometimes you manually place the wrapfigure environment, especially in cases where there is a page break. This actually means that you'll have to find the "right" place to put your figure.

I provide next an example for your document. I grayed out the three lines in the preamable, but you can modify it as you'd like. Notice first that I changed the \lipsum[1-2] to \lipsum[1-1] to make the figure stay on the same page and within page margins (~the manual placement I was talking about). Alternatively, put your figure first and then the text. Something like \begin{wrapfigure}...\end{wrapfigure}.. text...

You could also try R instead of r in the wrapfigure environment to make your figure float. The second optional argument specifies how much the figure can overhang in the margin. By setting it 0pt it will stay within margins. Finally, I set the width of the figure to 0pt and changed the width withing the \includegraphics.

To get all the subfloats vertical within a box, I just used a tabular environment and the \fbox.

Probably there are alternative ways to do this, for instance with the cutwin package, but I've never used it.

\documentclass[11pt]{amsart}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{floatrow}
%\DeclareFloatVCode{largevskip}
%{\vskip 20pt}
\captionsetup[figure]{font=small}
\usepackage{subfig}
\usepackage{wrapfig}

\usepackage{lipsum}

\begin{document}

\lipsum[1-1]

\begin{wrapfigure}{r}[0pt]{0pt}
\ffigbox[\FBwidth]
\fbox{
{\begin{tabular}{c}
\begin{subfloatrow}
\ffigbox[\FBwidth]
{\includegraphics[width=.4\textwidth]{example-image-a}}
{\caption{Subcaption 1}\label{sfig:ex1}}
\end{subfloatrow}\\

\begin{subfloatrow}
\ffigbox[\FBwidth]
{\includegraphics[width=.4\textwidth]{example-image-a}}
{\caption{Subcaption 2}\label{sfig:ex2}}
\end{subfloatrow}\\

\begin{subfloatrow}
\ffigbox[\FBwidth]
{\includegraphics[width=.4\textwidth]{example-image-a}}
{\caption{Subcaption 3}\label{sfig:ex3}}
\end{subfloatrow}
{\caption{asdf!} \label{fig:ex}}%
\end{tabular}}
}
\end{wrapfigure}

\lipsum[3-4]


Just for fun. This is one way to break a wrapped figure across a page. You could also do it with two wrapfigs, but odds are each would have to be placed in the middle of a paragraph.

\documentclass[11pt]{amsart}

\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{floatrow}
\DeclareFloatVCode{largevskip}
{\vskip 20pt}
\captionsetup[figure]{font=small}
\usepackage{paracol}
\usepackage{lipsum}

\newcommand{\nopar}{\bgroup\parfillskip=0pt\par\egroup}
\makeatletter
\newcommand{\setcaptype}[1]{\def\@captype{#1}}
\makeatother

\begin{document}

\lipsum[1-2]

Nam dui ligula, fringilla a, euismod sodales,
sollicitudin vel, wisi. Morbi auctor
lorem non justo. Nam lacus libero, pretium
at, lobortis vitae, ultricies et, tellus. Donec
aliquet, tortor sed accumsan bibendum, erat
ligula aliquet magna, vitae ornare odio metus
a mi. Morbi ac orci et nisl hendrerit mollis.
Suspendisse ut massa. Cras nec ante.
Pellentesque a nulla. \nopar

\columnratio{0.6,0.4}%
\begin{paracol}{2}
\switchcolumn
\bgroup
\parindent=0pt
\setcaptype{figure}%
\vfill
\begin{subfigure}{\columnwidth}
\includegraphics[width=\textwidth]{example-image-a}
\caption{Subcaption 1}\label{sfig:ex1}
\end{subfigure}

\begin{subfigure}{\columnwidth}
\includegraphics[width=\textwidth]{example-image-a}
\caption{Subcaption 2}\label{sfig:ex2}
\end{subfigure}

\begin{subfigure}{\columnwidth}
\includegraphics[width=\textwidth]{example-image-a}
\caption{Subcaption 3}\label{sfig:ex3}
\end{subfigure}
\caption{asdf!} \label{fig:ex}
\vfill
\egroup
\switchcolumn
\sloppy
\noindent
Cum sociis natoque
penatibus et magnis dis parturient montes,
nascetur ridiculus mus. Aliquam tincidunt
urna. Nulla ullamcorper vestibulum turpis.
Pellentesque cursus luctus mauris.

\lipsum[3]

felis erat, congue non, volutpat at,
tincidunt tristique, libero. Vivamus viverra
fermentum felis. Donec nonummy pellentesque
elit. Proin fermentum massa ac quam. Sed
diam turpis, molestie vitae, placerat a,
molestie nec, leo. Maecenas lacinia. Nam
ipsum ligula, eleifend at, accumsan nec,
suscipit a, ipsum. Morbi blandit ligula feugiat\nopar
\end{paracol}
\noindent
magna. Nunc eleifend consequat lorem. Sed
lacinia nulla vitae enim. Pellentesque
tincidunt purus vel magna. Integer non enim.
Praesent euismod nunc eu purus. Donec
bibendum quam in tellus. Nullam cursus
pulvinar lectus. Donec et mi. Nam vulputate
metus eu enim. Vestibulum pellen-
tesque felis eu massa.

\lipsum[4]

\end{document}

• This is a neat trick- as I mentioned in the comment above, I don't actually need to break the wrapfig right now, but it's really cool that you can do this. Thanks! – Irene Nov 11 '17 at 20:27