You can use a minipage
inside a \fcolorbox
; the wrapfigure
environment from the wrapfig
package can be used to let the text wrap around the box; inside the minipage
, the positioning for the image and the title can be achieved using, for example, \parbox
es. In the following example I defined a new environment mybox
with the help of the environ
package; the mandatory argument is used for the title of the box:
\documentclass{article}
\usepackage[verbose]{wrapfig}
\usepackage{bclogo}
\usepackage{environ}
\usepackage{lipsum}
\NewEnviron{mybox}[1]
{\wrapfigure{r}{.5\textwidth}
\setlength\fboxrule{1.5pt}
\fcolorbox{blue!70}{white}{%
\begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}
\parbox[t][1cm][t]{1cm}{\bccrayon}%
\parbox[t][1cm][t]{\dimexpr\linewidth-1cm\relax}{\bfseries#1}
\BODY
\end{minipage}}%
\endwrapfigure}
\begin{document}
\begin{mybox}{The Title}
\lipsum[2]
\end{mybox}
\lipsum[1-3]
\end{document}
Since the environment uses the wrapfig
package, the idiosyncrasies of wrapfig
apply here too (refer to the package documentation for details).
I don't know about mathescape
, but presumably you don't want/need to enter math mode anyway, since you just want to make a box.
So use escapechar=<char>
instead. I've turned your code snippets into an MWE to more clearly show the solution, but the same escapechar=|
(or some other character not used anywhere in the listing) is equally valid inside listing options
in your environment's definition.
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\begin{document}
\begin{tcblisting}{listing only,listing options={basicstyle=\ttfamily,escapechar=|}}
Now is the |\fbox{winter}| of our discontent
Made glorious summer by this sun of York;
\end{tcblisting}
\end{document}
Here's the full code made into a compilable example:
\documentclass[11pt]{article}
\usepackage[pdftex]{xcolor}
\definecolor{vlgray}{gray}{0.9}
\definecolor{lgray}{gray}{0.7}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable,listings}
\newenvironment{shk}{%
\tcblisting{listing only,colback=vlgray,colframe=vlgray,enlarge
top by=0mm,top=-2mm,bottom=2mm,enhanced,
after={\par\vspace{0.5\baselineskip}\noindent},
overlay={\node[draw,fill= black,yshift=4pt,xshift=-10pt,left,text=white,
anchor=east,font=\footnotesize\bfseries] at (frame.south east)
{Shakespeare};},
listing options={basicstyle=\small\ttfamily,breaklines=true,
language=HTML,escapechar=|},}}
{\endtcblisting}
\begin{document}
\begin{shk}
Now is the |\fbox{winter}| of our discontent
Made glorious summer by this sun of York;
\end{shk}
\end{document}
Best Answer
And here's one possibility using
mdframed
:Here's now a modification not using a theorem-like structure, but a simple environment with a mandatory argument to provide a title: