# How to make adjustbox work correctly with wrapfigure?

I have an adjustbox environment which gives colored background to content. It doesn't play nicely with wrapfigure. It overlaps with the content. Below is the mew.

\documentclass{scrartcl}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{tikz}

\newenvironment{bluebox}{%
\noindent
}{%

\egroup
}

\begin{document}
\lipsum[3-5]
\begin{wrapfigure}{L}{3.00in}
\begin{bluebox}
\lipsum[4]
\end{bluebox}
\end{wrapfigure}
\lipsum[3-5]

\end{document}


The output looks as follows: . The adjustbox overlaps with the rest of the content if used with wrapfigure. How can I fix this.

-

You have to use proper width for varwidth:

\adjustbox{innerenv={varwidth}{\dimexpr\linewidth-2\fboxsep-0.45cm\relax},
margin=\fboxsep+.25cm \fboxsep+.2cm,bgcolor=blue!10,frame,center}


I have subtracted the margin of adjustbox (\fboxsep+.25cm \fboxsep+.2cm,) from \linewidth. If you use 1.1\linewidth contents will be wider and hence the undesired effect.

Code:

\documentclass{scrartcl}
\usepackage{wrapfig}
\usepackage{kantlipsum}
\usepackage{tikz}

\newenvironment{bluebox}{%
\noindent
margin=\fboxsep+.25cm \fboxsep+.2cm,bgcolor=blue!10,frame,center}\bgroup
}{%
\egroup
}

\begin{document}
\kant[3-5]
\begin{wrapfigure}{L}{3.00in}
\begin{bluebox}
\kant[1]
\end{bluebox}
\end{wrapfigure}
\kant[3-5]

\end{document}


-
Upvoted for usage of the kantlipsum package. –  1010011010 May 25 '14 at 23:49