4

It seems that tcolorboxes work fine with wrapfigures as long as the wrapfigure is on the right side of the page. However, if I change the wrapfigure R option to L, then the tcolorbox continues to align at the left edge. What's the best workaround?

\documentclass{article}

\usepackage[margin=1in]{geometry} 
\usepackage{wrapfig}
\usepackage[most]{tcolorbox}
\usepackage{lipsum} 

\begin{document}

\begin{wrapfigure}[7]{L}{5cm}
  \tcbincludepdf[scale=1,size=tight,opacityframe=0]{example-image.pdf}
\end{wrapfigure}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. 
\begin{tcolorbox}
  Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo.
\end{tcolorbox}
\lipsum[1-2]

\end{document}

enter image description here

5

wrapfigure is nothing that works out of the box, it requires manual adjustment, as well as the surrounding boxes besides the wrapfigure. I suggest to use left skip=5.5cm and a narrower tcolorbox:

\documentclass{article}

\usepackage[margin=1in]{geometry} 
\usepackage{wrapfig}
\usepackage[most]{tcolorbox}
\usepackage{lipsum} 

\begin{document}

\begin{wrapfigure}[7]{L}{5cm}
  \tcbincludepdf[scale=1,size=tight,opacityframe=0]{example-image.pdf}
\end{wrapfigure}%
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. 
\begin{tcolorbox}[left skip=5.5cm,width=11cm]
  Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo.
\end{tcolorbox}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. 

\lipsum[1-2]

\end{document}

enter image description here

2
  • 1
    You can use \begin{tcolorbox}[enlarge left by =\csname @totalleftmargin\endcsname], then you don't have to guess (this doesn't work if the tcolorbox is the first thing beside the wrapfigure). – Ulrike Fischer Jan 2 '18 at 17:07
  • @UlrikeFischer: Thanks, I will change later on, for now I am occupied with other issues regarding my own code. enlarge left by is one of the 5000 keys of tcolorbox which are used pretty often, I assume? ;-) – user31729 Jan 3 '18 at 13:17
6

You can easily obtain what you want with the insbox plain TeX macro package. It defines an \InsertBoxL command (also \InsertBoxR and \InsertBoxC) to insert objects in a paragraph, with two mandatory arguments: the number of unshortened lines before insertion of the object, and this object. In addition an optional argument can be used: the number of supplementary shortened lines, in case TeX doesn't calculate the right number of shorter lines.

\documentclass{article}

\usepackage[showframe, margin=1in]{geometry}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\input{insbox.tex}

\begin{document}

\InsertBoxL{0}{\includegraphics[width = 5cm]{example-image.pdf}}[1]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.
\begin{tcolorbox}[width = \dimexpr\linewidth-5.2cm]
  Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo.
\end{tcolorbox}
\lipsum[1-2]

\end{document} 

enter image description here

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.