One possible solution, at least for requests 1, 2 3, and 5, using mdframed
:
\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{booktabs}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{lipsum}
\newcounter{exa}[section]
\renewcommand\theexa{\thesection.\arabic{exa}}
\newlength\mylen% to hols the width of the title
\newmdenv[
settings={\global\refstepcounter{exa}
\settowidth\mylen{\bfseries\color{cyan}Example~\theexa}},
leftline=false,
linecolor=cyan,
middlelinewidth=1pt,
innertopmargin=30pt,
innerbottommargin=10pt,
innerleftmargin=0pt,
skipbelow=1.3\topsep,
singleextra={
\path node[font=\bfseries\color{cyan},anchor=west,yshift=-12pt,inner sep=0pt] at (O|-P) {Example~\theexa};
\draw[ultra thick,cyan] ([yshift=.5\pgflinewidth]O|-P) -- ++(\mylen,0pt);
\draw[line width=2pt,white] (O) -- ($(P|-O)+(-2cm,0pt)$) node (A){};
\node[anchor=south west,fill=cyan,inner sep=3pt,outer sep=0pt] at (A) {};
},
firstextra={
\path node[font=\bfseries\color{cyan},anchor=west,yshift=-12pt,inner sep=0pt] at (O|-P) {Example~\theexa};
\draw[ultra thick,cyan] ([yshift=.5\pgflinewidth]O|-P) -- ++(\mylen,0pt);
},
secondextra={
\draw[line width=2pt,white] (O) -- ($(P|-O)+(-2cm,0pt)$) node (A){};
\node[anchor=south west,fill=cyan,inner sep=3pt,outer sep=0pt] at (A) {};
}
]{example}
\begin{document}
\section{Test Section}
\begin{example}
\lipsum[4]
\begin{center}
\captionof{table}{This is a table inside a \texttt{mdframed} environment}
\begin{tabular}{ccc}
\toprule
column1a & column2a & column3a \\
column1a & column2a & column3a \\
column1a & column2a & column3a \\
\bottomrule
\end{tabular}
\end{center}
\end{example}
\lipsum*[2-3]
\setcounter{exa}{23}% just for the example
\begin{example}
\lipsum*[1-4]
\begin{center}
\includegraphics[width=6cm]{ctanlion}
\captionof{figure}{This is a figure inside a \texttt{mdframed} environment}
\end{center}
\lipsum*[5-6]
\end{example}
\lipsum*[2]
\end{document}

Floats won't be allowed inside the mdframed
environment; as has been mentioned in comments, this is not a restriction; in fact, it wouldn't make much sense. However, as the example demonstrates, one can still have tabular material and images with captions, using the \captionof
from the caption
or capt-of
packages.
CTAN lion drawing by Duane Bibby.
SMH: Due to a reference issue, I edited the code.
Another approach is the suggest package tcolorbox
. With the newest version of the package you can use the following code. It has the same limitation like mdframed
.
\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{mwe}%load graphix,lipsum,...
\usepackage{xcolor}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\tcbuselibrary{breakable}
\newcounter{example}[section]
\renewcommand\theexample{\thesection.\arabic{example}}
\tcbset{examplebox/.style={%
title={Example~\refstepcounter{example}\theexample},
breakable,
leftrule=0pt,
arc=0pt,
colback=white,
colframe=cyan,
enhanced,
colbacktitle=white,
coltitle=cyan,
titlerule=0pt,
enlarge left by=-4mm,
width=\linewidth+4mm,
enlarge top by=2pt,
overlay unbroken={\draw[cyan,line width=2pt] (frame.north west)++(0,0.25mm) --++(4cm,0pt);
\draw[white,line width=10mm] (frame.south west) --++(8cm,0pt) node (P) {};
\fill[cyan] (P) rectangle ++(6pt,6pt) ;},%
overlay first={\draw[cyan,line width=2pt] (frame.north west)++(0,1pt) --++(4cm,0pt);},%
overlay last={\draw[white,line width=10mm] (frame.south west) --++(8cm,0pt) node (P) {};
\fill[cyan] (P) rectangle ++(6pt,6pt) ;},%
}%
}
\newenvironment{example}{%
\tcolorbox[examplebox]}%
{\endtcolorbox}
\begin{document}
\section{Test Section}
\begin{example}
\lipsum[4]
\begin{center}
\captionof{table}{This is a table inside a \texttt{tcolorbox} environment}
\begin{tabular}{ccc}
\toprule
column1a & column2a & column3a \\
column1a & column2a & column3a \\
column1a & column2a & column3a \\
\bottomrule
\end{tabular}
\end{center}
\end{example}
\lipsum*[2-3]
\begin{example}
\lipsum*[1-4]
\begin{center}
\includegraphics[width=6cm]{example-image-a}
\captionof{figure}{This is a figure inside a \texttt{tcolorbox} environment}
\end{center}
\lipsum*[5-6]
\end{example}
\lipsum*[2]
\end{document}
mdframed
package would certainly help here.floats
can not go inmdframed
environments, but I wouldn't say that it has 'serious flaws'. It does more than any other framing package available. Putting afloat
in aframe
is very trick- putting aframe
in afloat
is much easier\captionof
of thecaption
package is what you're looking for.