[Tex/LaTex] customized caption and label for adjustbox

adjustboxcaptionslabels

The question is a follow up of the question posted here how to make adjustbox work correctly .

\documentclass{scrartcl}
\usepackage{adjustbox}
\usepackage{wrapfig}
\usepackage{lipsum}
\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}
\lipsum[3-5]
\begin{wrapfigure}{L}{3.00in}
\begin{bluebox}
 { \bf{Box 1: My caption here}}\\
\tikz \draw[line width=.1cm, red] (0,0) -- (\linewidth,0);
\lipsum[4]
\end{bluebox}
\end{wrapfigure}
\lipsum[3-5]
\end{document}

This is rendered as follows:
enter image description here

If it is not an overkill then is it possible that Box 1 becomes the label and the text following it is the caption.

Best Answer

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}

enter image description here