# How to defining additional float environment like figures and tables?

I have found this tread on how to construct a box around content and liked the idea quite a lot. I have used it on a few places but ran into a little problem now.

I have a box that is about 3/4 of a page tall and kind of rips my document apart. What I would like to do is that this box is floating while all of the other boxes should remain where they are.

It would also be great if these boxes could have captions like tables have but I would like for them to be placed in the "title" section of the frame. If that is possible.

Below I have attached the source code of an example about the placement. In the first section there is to much white on the first page and in the second section it's not all that much better.

            \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{lipsum}
\usepackage{tcolorbox}
\newtcolorbox{mybox}{colback=black!5!white,colframe=blue!75!black}
\newtcolorbox{myboxtitle}[1]{colback=green!5!white,colframe=green!75!white,title=#1} %fonttitle=\bfseries

\begin{document}

\section{How it is}
\lipsum[7]
\begin{myboxtitle}{Naming Convention for CC}
\lipsum[2]
\end{myboxtitle}
\lipsum[8]
\begin{myboxtitle}{Naming Convention for CC}
\lipsum[3]
\begin{minipage}[t][4.2cm][c]{\linewidth}
\end{minipage}
\lipsum[6]
\end{myboxtitle}
\lipsum[7-10]

\newpage
\section{How it would be better}
\lipsum[7]
\begin{figure} %this should be the new environment. Would be great to combine with the box
\begin{myboxtitle}{Naming Convention for CC}
Well, this should not float to the top!
\end{myboxtitle}
\end{figure}
\lipsum[8]
\begin{figure}
\begin{myboxtitle}{Naming Convention for CC}
\lipsum[3]
\begin{minipage}[t][4.2cm][c]{\linewidth}
\huge This box should not be alone on one page.
\end{minipage}
\lipsum[6]
\end{myboxtitle}
\end{figure}
\lipsum[7-12]

\end{document}


• Package tocbasic provides a command \DeclareNewTOC that sets up a new environment, the name, the name for the list of, the list of, the counter ... – Johannes_B Apr 9 '15 at 16:51
• @Johannes_B Thanks, I will have a look at it. – MatoBehr Apr 9 '15 at 16:58
• @MatoBehr: tcolorbox can be made floating if float option is used ;-) – user31729 Apr 9 '15 at 19:17
• Please accept one of the solutions below or give other feedback – user31729 Apr 16 '15 at 12:14
• @ChristianHupfer I have used the solution suggested by Johannes_B which works quite nicely. I am sorry to say that I have not tried any of the others thereafter. – MatoBehr Apr 16 '15 at 12:17

Not quite finished, but correctly floating, as I would say. Just use the float option of tcolorbox environments.

 \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\newtcolorbox{mybox}{colback=black!5!white,colframe=blue!75!black,float}
\newtcolorbox[auto counter,number within=section]{myboxtitle}[2][]{colback=green!5!white,colframe=green!75!white,title={#2},float,#1} %fonttitle=\bfseries

\begin{document}

\section{How it is}
\lipsum[7]
\begin{myboxtitle}{Naming Convention for CC}
\lipsum[2]
\end{myboxtitle}
\lipsum[8]
\begin{myboxtitle}{Naming Convention for CC}
\lipsum[3]
\begin{minipage}[t][4.2cm][c]{\linewidth}
\end{minipage}
\lipsum[6]
\end{myboxtitle}
\lipsum[7-10]

\newpage
\section{How it would be better}
\lipsum[7]
\begin{myboxtitle}{Naming Convention for CC}
Well, this should not float to the top!
\end{myboxtitle}
\lipsum[8]
\begin{myboxtitle}[floatplacement=ht]{Naming Convention for CC}
\lipsum[3]
This box should not be alone on one page.
\lipsum[6]
\end{myboxtitle}
\lipsum[7-12]

\end{document}


May be the float package is useful for you:

\documentclass{article}
\usepackage{float,lipsum,graphicx}
\floatstyle{ruled} % try boxed
\newfloat{fancyfloat}{tb}{fan}[section]
\floatname{fancyfloat}{Fancy float}
\begin{document}
\listof{fancyfloat}{List of fancy floats}

\section{Lore ipsum}

\lipsum[1]

\begin{fancyfloat}
\hfill Some dummy content \dotfill\vrule
\centering
\begin{tabular}{llll}
11 & 12 & 13 & 14\\
21 & 22 & 23 & 24\\
31 & 32 & 33 & 34\\
41 & 42 & 43 & 44\\
\end{tabular}\hfill
\caption{This is a fancy float}
\end{fancyfloat}

\lipsum[2]

\begin{fancyfloat}[H]
\caption{This is a other fancy float}
\includegraphics[height=2cm]{example-image-a}\hfill
\includegraphics[height=2cm]{example-image-b}\hfill
\includegraphics[height=2cm]{example-image-c}
\end{fancyfloat}
\lipsum[15-30]
\end{document}


You can control the placement (more or less) using the figure options.

        \usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{lipsum}
\usepackage{tcolorbox}
\newtcolorbox{mybox}{colback=black!5!white,colframe=blue!75!black}
\newtcolorbox{myboxtitle}[1]{colback=green!5!white,colframe=green!75!white,title=#1} %fonttitle=\bfseries

\begin{document}

\section{How it would be better}
\lipsum[7]
\begin{figure}[hbp] %this should be the new environment. Would be great to combine with the box
\begin{myboxtitle}{Naming Convention for CC}
Well, this should not float to the top!
\end{myboxtitle}
\end{figure}
\lipsum[8]
\begin{figure}[!t]
\begin{myboxtitle}{Naming Convention for CC}
\lipsum[3]
\begin{minipage}[t][4.2cm][c]{\linewidth}
\huge This box should not be alone on one page.
\end{minipage}
\lipsum[6]
\end{myboxtitle}
\end{figure}
\lipsum[7-12]

\end{document}