2

I want to create a custom tcolorbox that has an icon in the top left corner. For the sake of simplicity I will use some tikzpicture to illustrate what I mean. But reading the tcolorbox manual I can't find a way to make the text in the box wrap the figure. The only way of fitting the figure into the box is by indenting the whole box content via "leftupper=[length]".

enter image description here

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins}

%%% My custom box

\newtcolorbox{mybox}{%
breakable, 
fonttitle=\bfseries,
colback=red!5!white,
enhanced jigsaw,
colframe=red!50!black,
colbacktitle=red!50!black, 
colframe=red!50!black,
opacityback=0.35,
leftupper=16mm,
title=test}

%%% The command for the image

\newcommand{\test}{\begin{tikzpicture} \path[use as bounding box] (-.1,1.6) rectangle +(0.3,.3); \draw[fill=black] (0,0) circle (.5cm); \end{tikzpicture}}

\begin{document}

\test
\begin{mybox}This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. This is some random text. \end{mybox}

\end{document}

Buh
  • 327

1 Answers1

3

Something like this?

\documentclass{article}

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

\begin{document}

\begin{tcolorbox} \begin{wrapfigure}[11]{L}{5cm} \includegraphics[width=\linewidth]{example-image} \end{wrapfigure}% \lipsum[1-2] \end{tcolorbox}

\end{document}

enter image description here

Ignasi
  • 136,588
  • I'd have to make some adjustments to get what I want eventually but that's actually a pretty easy way of doing it. Thanks! Completely forgot the wrapfigure package. – Buh Sep 10 '20 at 17:39
  • One more question just came to mind: Is there a way to manage the spacing above the image? I want to move it closer to the upper border of the box. Using something like vspace however also then moves the text (into the border). – Buh Sep 11 '20 at 01:05
  • @Buh I don't know where this vertical space comes. It seems that is from wrapfig, you can test with the same code without tcolorbox and the figure is placed lower than first line. – Ignasi Sep 11 '20 at 06:45
  • @Buh Taken from https://tex.stackexchange.com/a/176346/1952, this \begin{wrapfigure}[10]{L}{5cm}\centering\vspace{-1em}\includegraphics[width=1\linewidth,valign=t]{example-image}\end{wrapfigure} seems to work. – Ignasi Sep 11 '20 at 06:52
  • That worked for me, thanks again! – Buh Sep 11 '20 at 11:17