1

This question is the continuation of the one posted here. How can I add a caption to the figures as shown below?

enter image description here

2

The technique followed below builds on what is discussed in Wrapping two figures in one paragraph:

enter image description here

\documentclass{article}

\usepackage{graphicx,caption}

% https://tex.stackexchange.com/a/133660/5764
\makeatletter
\def\newparshape{\parshape\@npshape0{}}
\def\@npshape#1#2#3{\ifx\\#3\expandafter\@@@npshape\else\expandafter\@@npshape\fi
  {#1}{#2}{#3}}
\def\@@npshape#1#2#3#4#5{%
  \ifnum#3>\z@\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
  {\expandafter\@@npshape\expandafter{\the\numexpr#1+1\relax}{#2 #4 #5}{\numexpr#3-1\relax}{#4}{#5}}%
  {\@npshape{#1}{#2}}}
\def\@@@npshape#1#2#3{#1 #2 }
\makeatother

\begin{document}
\sloppy
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae mauris risus. Sed 
varius dui diam, sit amet volutpat risus euismod in. Ut ac dui fermentum, laoreet arcu 
volutpat, vestibulum urna. Integer vitae odio at neque imperdiet sollicitudin vel vel enim. 
Nullam sodales facilisis magna sit amet tempor. Morbi ut nulla sem. Aliquam sagittis, 
lacus auctor tincidunt semper, odio dui lacinia lectus, quis tempus quam leo sed mi. 
Maecenas eu mauris dolor.

\newparshape
  {9}{\dimexpr6cm+\tabcolsep}{\dimexpr\textwidth-6cm-\tabcolsep}% Unique to top-left image
  {2}{\dimexpr6cm+\tabcolsep}{\dimexpr\textwidth-9cm-2\tabcolsep}% Between top-left and bottom-right image
  {6}{0pt}{\dimexpr\textwidth-3cm-\tabcolsep}\\% Unique to bottom-right image
\noindent\leavevmode
\llap{%
  \raisebox{\dimexpr-\height+\ht\strutbox}[0pt][0pt]{%
    \begin{minipage}{6cm}
      \centering
      \includegraphics[width=6cm,height=9\baselineskip]{example-image-a} \\
      \captionof{figure}{A caption}
    \end{minipage}%
  }%
  \hspace*{\tabcolsep}%
}%
Pellentesque porta pharetra leo, ut accumsan diam feugiat sit amet. Ut mattis nulla sed 
sapien suscipit, eu sodales elit cursus. Vestibulum sit amet sollicitudin nisl. Aenean 
vestibulum purus sed tincidunt convallis. Aliquam ut sodales risus. Mauris in mauris a 
ante venenatis faucibus. Ut nunc ante, cursus sit amet iaculis eget, imperdiet quis libero. 
Pellentesque laoreet dolor eget consectetur vehicula. Maecenas ultrices vehicula ultricies. 
Morbi cursus risus ut eros placerat condimentum. Mauris nec varius lectus. Nulla adipiscing 
porttitor tellus vitae congue. Aliquam commodo gravida erat, lacinia vehicula enim mollis 
nec. Nulla sed metus gravida, faucibus neque eu, rutrum purus. Integer ornare nunc vel 
dolor lacinia, sit amet venenatis turpis porttitor. Fusce lobortis magna eget odio iaculis, 
sed blandit urna dictum.
\hfill\rlap{\hspace*{\tabcolsep}%
  \raisebox{\dimexpr-\height+8\baselineskip+\ht\strutbox}[0pt][0pt]{%
    \includegraphics[width=3cm,height=9\baselineskip]{example-image-b}}}

Morbi id dolor vulputate, euismod sapien nec, condimentum tellus. Fusce tincidunt sem non 
turpis ultricies, eu egestas lorem posuere. Integer risus lectus, gravida vel tincidunt sit 
amet, vestibulum eget leo. Curabitur vitae enim sem. Vivamus rutrum velit eget justo 
condimentum egestas. Phasellus sit amet lacus mauris. Sed quis aliquet tellus. In mauris 
ante, porttitor sit amet rhoncus et, ultrices quis elit. Proin sed aliquet eros.
\end{document}

The image is placed inside a minipage of predefined width (which shouldn't be a problem since the \newparshape has predefined line widths). caption provides \captionof{<float>}[<ToC caption>]{<caption>} that allows one to set a float <caption> inside a group even though you're not inside a <float>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.