# Problem with wrapfigure and chemstyle

I have a problem with wrapping text around figures. The following example demonstrates the problem, the text is not wrapped around the figure. By disabling the chemstyle package, everything works as it should be. However, I am dependent on the chemstyle package. Do you know any workaround or why the chemstyle package prevents the text to wrap around the included figure?

\documentclass[12pt,a4paper,captions=nooneline,twoside]{scrreprt}
\usepackage[onehalfspacing]{setspace}
\usepackage[paper=a4paper,left=30mm,right=20mm,top=25mm,bottom=25mm]{geometry}

\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{chemstyle}

\begin{document}

\chapter{Test}

\lipsum[1]
\begin{wrapfigure}{r}{0.5\textwidth}
\begin{center}
\includegraphics[width=0.48\textwidth]{figure}
\end{center}
\caption{A gull}
\end{wrapfigure}
\lipsum[1]

\end{document}

• It does not seem to be chemstyle it self but chemscheme (which is loaded by chemstyle). Just to reduce the MWE even further (note that yuo can replace the image by \rule{5cm}5cm}, and it might also be an idea to use a standard class instead of scrreprt just ot make sure it is not something from there which is interfering Jul 10, 2020 at 10:44
• We can reduce further, it is not chemscheme either, just lost floatrow Jul 10, 2020 at 10:47
• @daleif hm sounds like I am in the right place. I ll hope there is a workaround for this problem
– MJK
Jul 10, 2020 at 11:37
• You can search the site for wrapfig plus floatrow Jul 10, 2020 at 11:42
• What happens for you in your example? For me it semi-works, but with extra white space: The extra space above and below is produced by the center environment. The space on the sides is caused by the chemstyle package (probably the caption package) REDEFINING THE wrapfig environment, and changing \textwidth within it. Jul 10, 2020 at 22:03

I got no clarification to my question, so I'll assume that MJK's problem was what I saw when I ran the sample.

There are extra spaces above and below the picture caused by the center environment. It should be replaced by a \centering command.

The picture is too small because the floatrow package redefines the wrapfigure environment to change the value of \textwidth into the width of the figure. It does so for all figure types, which is confusing in twocolumn documents! (In the question, the width 0.5\textwidth would be bad in a twocolumn document also.)

Living with floatrow.sty's funny \textwidth means avoiding it and using more appropriate line width parameters.

\begin{wrapfigure}{r}{0.5\columnwidth}
\centering
\includegraphics[width=0.95\linewidth]{figure}
\caption{A gull}
\end{wrapfigure}


Here is a workaround, with the \InsertBoxR command from the plain TeX macro package. This command takes two mandatory arguments: the number of lines at the beginning of the paragraph that remain unshortened, and the box to be inserted, and one optional argument (at the end!) – the number of supplementary lines to be shortened, in case IeX does not calculate the correct number of shorter lines. It does not seem to conflict with chemstyle.

\documentclass[12pt,a4paper,captions=nooneline,twoside]{scrreprt}
\usepackage[onehalfspacing]{setspace}
\usepackage[paper=a4paper,left=30mm,right=20mm,top=25mm,bottom=25mm]{geometry}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{chemstyle}
\input{insbox.tex}

\begin{document}

\chapter{Test}

\lipsum[1]

\InsertBoxR{2}{%
\parbox{0.5\textwidth}{\raggedleft\includegraphics[width=0.48\textwidth]{TasmanianDevil}\\
\captionof{figure}{The Tasmanian Devil}}
}[5]
\lipsum[1]

\end{document}