I am a fairly proficient latex user, but have stumbled across a formatting challenge outside my experience.
I am trying to create a custom "box" float - similar to what one might see in children's science books such as the Dorling Kindersley science books.
I want to include both text and subfloats within this float and would prefer to have the text wrap around the subfloats. Is there a way to do this? I've done' a fair amount of searching online and am coming up empty-handed, so I'm wondering if perhaps there is a fundamentally different way to approach this problem.
Ideally I would like to know:
- How to individually wrap text around each of the subfigures captioned "Wrap?" in the MWE below.
- How to wrap around a group of subfigures such as the minipage in the MWE below.
And advice on how to do this or where to look would be welcome.
I've included a MWE using minipages and without any wrapping functionality.
The problem with the approach in this example is:
- I'd to have the flexibility to not arrange figures in a line
- If I settle with a lined-up format, as shown, there is a break in the text.
Thanks!
\documentclass{article}
\usepackage{amsmath}
%For use of "\includegraphics"
\usepackage{graphicx}
%For filler text
\usepackage{lipsum}
%For textcolor
\usepackage{xcolor}
%To force figure position and for "\restylefloat"
\usepackage{float}
%To define custom float environments
\usepackage{newfloat}
%For "DeclareCaptionSubtype" below
\usepackage{caption}
%For subfigures
\usepackage{subcaption}
%Wrap text around figures
%\usepackage{wrapfig}
% Set the color of the "shaded" environment
\colorlet{shadecolor}{black!5}
%For use of the "shaded" environment
\usepackage{framed}
%Define the "mybox" environment
\DeclareFloatingEnvironment[
fileext=lob, %An auxiliary file that stores the "list of boxes" (.lob). This abbreviation is user defined and analogous to .lof (list of figures) and .lot (list of tables0.
listname={List of Boxes}, %Title for the TOC list of this type of float
placement={htbp},%All possible placement options
name=Box %Name of float type - to appear in caption
]{mybox} %handle for this float environment
%If you would like the "boxing" float style to be boxed
%Note: \floatstyle applies on all subsequent \newfloat commands
\floatstyle{boxed}
\restylefloat{mybox}
%Announce the "mybox" float type to subcaption and create the subtextbox environment
\DeclareCaptionSubType[alph]{mybox}
\renewcommand\thesubmybox{\alph{submybox}}
%Figure Path
%\newcommand{\FigurePath}{Absolute File Path Here}
%Filler Art
\newcommand{\FillerArt}{example-image}
\begin{document}
\begin{mybox}
\begin{shaded*}
\footnotesize
\begin{center} \textbf{This is a Title}\end{center}
\lipsum[1]
\begin{minipage}[t]{.3\textwidth}
\centering
\begin{submybox}{\textwidth}
\centering
\includegraphics[width=\textwidth]{\FillerArt}
\caption{\textbf{Individual subfloat to wrap.}}
\label{}
\end{submybox}
\end{minipage}
\begin{minipage}[t]{.58\textwidth}
\lipsum[1]
\end{minipage}\\
\begin{minipage}{.3\textwidth}
\begin{submybox}{\textwidth}
\centering
\includegraphics[width=\textwidth]{\FillerArt}
\caption{\textbf{1 of 2 to wrap as a group.}}
\label{}
\end{submybox}
\begin{submybox}{\textwidth}
\centering
\includegraphics[width=\textwidth]{\FillerArt}
\caption{\textbf{2 of 2 to wrap as a group.}}
\label{}
\end{submybox}
\end{minipage}
\begin{minipage}[t]{.58\textwidth}
\lipsum[1]
\end{minipage}\\
\begin{minipage}{\textwidth}
\centering
\begin{submybox}{.3\textwidth}
\centering
\includegraphics[width=\textwidth]{\FillerArt}
\caption{\textbf{Test.}}
\label{}
\end{submybox}
\begin{submybox}{.3\textwidth}
\centering
\includegraphics[width=\textwidth]{\FillerArt}
\caption{\textbf{Test.}}
\label{}
\end{submybox}
\begin{submybox}{.3\textwidth}
\centering
\includegraphics[width=\textwidth]{\FillerArt}
\caption{\textbf{Test.}}
\label{}
\end{submybox}
\end{minipage}
\end{shaded*}
\caption{\textbf{Box Test.}}
\label{box:test}
\end{mybox}
\end{document}