JeT
Question following this one https://topanswers.xyz/tex?q=1410 that works perfectly to display in `tcolorbox`, `example`, `definition` environments, but not floating ones like `figure` or `table`.
How can we include the `\caption` of the `float` in title of the tcolorbox.
Can it float as the float does ?
```
\documentclass[11pt]{article}
\usepackage{xcolor}
\usepackage{float}
\usepackage{graphics}
\usepackage[envcountsect]{beamerarticle}
\usepackage{tcolorbox}
\usepackage{xparse}
\mode<article>{
\renewtcolorbox{figure}[1][]
{colback=green!5!white, colframe=green!75!black,fonttitle=\bfseries, colbacktitle=green!85!black,
title=#1}
}
\begin{document}
\begin{figure}[htp]
\centering
\includegraphics[width=0.50\textwidth]{example-image}
\caption{My caption}
\end{figure}
\begin{frame}
{Title of the frame}
{Subtitle of the frame}
\begin{block}{My block}
My long definition that can take multiple lines,
\end{block}
\begin{itemize}
\item first
\item Second
\item third
\end{itemize}
\begin{example}[My example]
My long example that can take multiple lines,
\end{example}
\end{frame}
\end{document}
```
Top Answer
samcarter
You could define a new environment `myfigure` that becomes either a floating tcolorbox in article mode or a normal figure in beamer mode:
```
\documentclass[11pt]{article}
%\documentclass{beamer}
\usepackage[envcountsect]{beamerarticle}
\usepackage{tcolorbox}
\usepackage{xparse}
\mode<article>{
\newtcolorbox[blend into=figures]{myfigure}[2][]{float=htbp,capture=hbox,
title={#2},every float=\centering,#1}
}
\usepackage{environ}
\mode<beamer>{%
\NewEnviron{myfigure}[1]{%
\begin{figure}%
\BODY
\caption{#1}%
\end{figure}%
}
}
\begin{document}
\begin{frame}{Title of the frame}
{Subtitle of the frame}
\begin{myfigure}{My caption}
\includegraphics[width=0.50\textwidth]{example-image}
\end{myfigure}
\begin{block}{My block}
My long definition that can take multiple lines,
\end{block}
\begin{itemize}
\item first
\item Second
\item third
\end{itemize}
\begin{example}[My example]
My long example that can take multiple lines,
\end{example}
\end{frame}
\end{document}
```
![Screen Shot 2020-10-13 at 17.20.42.png](/image?hash=135685ac7765c578982737b6154d5a9f19b30dec512cd8a6abce7d8558659606)