This can be done using the adjustbox
package. The solution is similar to the one of Werner but saves you some manual work with saveboxes. Note that adjustbox
v1.0 also includes a figure
key which allows to add the figure environment automatically as well.
\documentclass{article}
\usepackage{adjustbox}
\usepackage{blindtext}
\begin{document}
\blindtext
\begin{figure}[ht]
\begin{adjustbox}{addcode={\begin{minipage}{\width}}{\caption{%
Here is a caption of the figure which is so long that
it has to be wrapped over multiple lines, but should
not exceed the width (height after the rotation) of the image.
}\end{minipage}},rotate=90,center}
\includegraphics[scale=.6]{example-image}%
\end{adjustbox}
\end{figure}
\blindtext
\end{document}
Since you are constructing a titled colored box, I would suggest to consider the packages mdframed
or tcolorbox
for your task.
The following example code uses tcolorbox
version 3.04 (2014/05/18)
. An automatically numbered bluebox
is contructed which includes the wrapfigure
and takes 4 parameters described in the following code.
For easy references, the cleveref
package is also included which defines the \Cref
macro used in the example.
\documentclass{scrartcl}
\usepackage[skins,xparse]{tcolorbox}% version 3.04
\usepackage{wrapfig,cleveref}
\usepackage{lipsum}
% optional #1: width of the box
% optional #2: further tcolorbox options
% mandatory #3: title (caption text)
% mandatory #4: label of the box
\NewTColorBox[auto counter,
Crefname={Box}{Boxes},crefname={box}{boxes}]% <-- replace with your boxname
{bluebox}{ O{3.00in} O{} m m }{%
enhanced,width=#1,before=\wrapfigure{L}{#1},after=\endwrapfigure,
size=fbox,left=0.25cm,right=0.25cm,toptitle=0.2cm,bottom=0.2cm,
top=0.2cm,bottomtitle=0.2cm,
colframe=blue!10!white,interior hidden,coltitle=black,fonttitle=\bfseries,
title code={\draw[line width=.1cm,red,shorten <=0.25cm+3pt,shorten >=0.25cm+3pt]
(title.south west)--(title.south east);},
borderline={0.4pt}{0pt}{black,sharp corners},
title={Box~\thetcbcounter: #3},label={#4},#2}
\begin{document}
Box~\ref{boxlabel} defines all the terminologies used in this paper.
\Cref{boxlabel} defines all the terminologies used in this paper.
\lipsum[4-5]
\begin{bluebox}{My caption here}{boxlabel}
\lipsum[4]
\end{bluebox}
\lipsum[3-5]
\end{document}
Best Answer
You mean like this?