# How do I wrap a picture when it is right after environment \begin?

I am trying to wrap pictures in environments. I've seen people there recommend using insbox.tex in different answers. Everything is fine with my code below. However, when picture is introduced right after \begin{group} it simply doesn't work.

Edit: I don't to \leavevmode that.

Look at my MWE:

\documentclass{book}
\usepackage{amsthm}
\usepackage{lipsum}
\newtheorem{thm}{Theorem}
\usepackage{graphicx}
\usepackage[font=footnotesize]{caption}
\input{insbox.tex}
\usepackage{threeparttable}
\usepackage{xargs}

\newcommand\insertpictureR[3][5]{
\InsertBoxR{0}{\begin{threeparttable}\begin{tabular}{c@{}}\includegraphics[width=#3\textwidth]{#2}\end{tabular}\captionof{figure}{}\end{threeparttable}}[#1]%
}
\newcommand\insertpictureL[3][5]{
\InsertBoxL{0}{\begin{threeparttable}\begin{tabular}{c@{}}\includegraphics[width=#3\textwidth]{#2}\end{tabular}\captionof{figure}{}\end{threeparttable}}[#1]%
}

\begin{document}
\begin{thm}
\insertpictureR{example-image-a}{0.2}
\lipsum[1]
\end{thm}

\begin{proof}
\insertpictureL{example-image-a}{0.2}
\lipsum[1]
\end{proof}
\end{document}

• Why do you need a threeparttable environment? – Bernard Jun 27 at 21:02
• @Bernard wrapfig package in this case solve the problem? My best regards. – Sebastiano Jun 27 at 21:03
• @Sebastiano: I doubt that, because theorem-like structures are lists, as a last resort. That's why insbox often works better, because it's based on plain TeX. – Bernard Jun 27 at 21:17
• @Bernard to be honest, it is just a function from your answer long ago. tex.stackexchange.com/a/297595/98432 I still use it :) But today I've got this problem. Well, probably I need to try another approach at all... like dividing it into 2 minipages, but that seems to be so unnecessary. – Lust_For_Love Jun 27 at 21:26

You were missing a \leavevmode and some other goodies. Note your macro seems to systematically require using the optional argument (maybe the caption height is not taken into account correctly?).

\documentclass{book}
\usepackage{amsthm}
\usepackage{lipsum}
\newtheorem{thm}{Theorem}
\usepackage{graphicx}
\usepackage[font=footnotesize]{caption}
\input{insbox.tex}
\usepackage{threeparttable}
\usepackage{xargs}

\newcommand\insertpictureR[3][5]{
\InsertBoxR{0}{\begin{threeparttable}\begin{tabular}{c@{}}\includegraphics[width=#3\textwidth]{#2}\end{tabular}\captionof{figure}{}\end{threeparttable}}[#1]%
}
\newcommand\insertpictureL[3][5]{
\InsertBoxL{0}{\begin{threeparttable}\begin{tabular}{c@{}}\includegraphics[width=#3\textwidth]{#2}\end{tabular}\captionof{figure}{}\end{threeparttable}}[#1]%
}

\begin{document}

\begin{thm} \leavevmode
\insertpictureR[3]{example-image-a}{0.2}\noindent
\lipsum[1]
\end{thm}%

\begin{proof}
\leavevmode\insertpictureL[3]{example-image-a}{0.2}\noindent
\lipsum[1]
\end{proof}

\end{document}


• oh no, I don't want to leavemode that... should have said that. I don't like leaving an almost empty line. – Lust_For_Love Jun 27 at 21:29
• and yes, threeparttable makes counting lines wrong – Lust_For_Love Jun 27 at 21:29
• I understand, but the only case I know how to deal with are standard lists, because we can easily play with right margins thanks to enumitem. – Bernard Jun 27 at 21:39
• Note the image can start at the label line if you recode your command as \InsertBoxR{-1}{...}. So the label will feel less lonely… – Bernard Jun 27 at 21:49
• @JohnKormylo: Does this way eliminate the problem due to a list environment? – Bernard Jun 28 at 8:11