Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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{adjustbox}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{tikz}


\newenvironment{bluebox}{%
    \noindent
    \adjustbox{innerenv={varwidth}[c]{1.1\linewidth},margin=\fboxsep+.25cm \fboxsep+.2cm,bgcolor=blue!10,frame,center}\bgroup
}{%

    \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: wrapfigure_and_adjustbox. The adjustbox overlaps with the rest of the content if used with wrapfigure. How can I fix this.

share|improve this question

1 Answer 1

up vote 9 down vote accepted

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{adjustbox}
\usepackage{wrapfig}
\usepackage{kantlipsum}
\usepackage{tikz}


\newenvironment{bluebox}{%
    \noindent
    \adjustbox{innerenv={varwidth}{\dimexpr\linewidth-2\fboxsep-0.45cm\relax},
    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}

enter image description here

share|improve this answer
    
Upvoted for usage of the kantlipsum package. –  1010011010 May 25 at 23:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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