# Numerated Boxed Example Macro with Tikz Arrows

I would like to recreate this image in the form of a macro:

So far I have skeleton:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\usepackage{amsmath,amssymb}

\newcounter{exnum}

\setcounter{exnum}{0}

\newcommand{\Example}[1]{\begin{tikzpicture} \stepcounter{exnum}
\node [mybox1] (box){%
\begin{minipage}{\textwidth}
{#1}
\end{minipage}
};
\node[fancytitle1, right=10pt] at (box.north west) {Example
\arabic{exnum}:};
\end{tikzpicture}}
\begin{document}

% Define box and box title style
\tikzstyle{mybox1} = [draw=red, fill=blue!20, very thick,
rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle1} =[fill=red, text=white]

\Example{Text}
\Example{Text}
\Example{Text}
\end{document}


This produces:

I need help with the style plus suggestions on the program. Not sure why the first example is shifted slightly?

Like this?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\tikzset{exbox/.style = {
titlebox/.style = {draw, rounded corners, semithick, fill=white,
font=\bfseries, inner sep=5pt,
node contents={Exercise~\theex}
},
arr/.style = {{Triangle[angle=45:1pt 3]}-{Triangle[angle=45:1pt 3]},
rounded corners, semithick},
exercise/.style = {text width=\dimexpr\linewidth-19pt,
inner ysep=\baselineskip, inner xsep=5pt,
align=justify}
}
}
\newcommand\EX[1]{
\refstepcounter{ex}
\noindent%
\begin{tikzpicture}[exbox]
\node (ex) [exercise] {#1};
{\lipsum[1]};
\draw[arr]  ([yshift=-\baselineskip] ex.north west) --
(ex.north west) --
(ex.north east) node[titlebox,anchor=west, pos=0.1] --
([yshift=-\baselineskip] ex.north east);
\draw[arr] ([yshift=\baselineskip] ex.south west) --
(ex.south west) --
(ex.south east) node[titlebox,anchor=east, pos=0.9] --
([yshift=\baselineskip] ex.south east);
\end{tikzpicture}
\medskip\par}% end new command

\usepackage{lipsum}
\newcounter{ex}

\begin{document}
\EX{\lipsum[1]}
\EX{\lipsum[2]}
\end{document}


One good candidate for this is tcolorbox. I kept your numbering scheme with exnum but you might be better off if you used a theorem-like tcolorbox. tcolorbox is based on TikZ and allows you to do everything you can do in TikZ but has extended support for boxes in addition.

\documentclass{article}
\usepackage[most]{tcolorbox}
\newcounter{exnum}
\setcounter{exnum}{0}
\newtcolorbox{exbox}[1][]{%
enhanced,
before skip=10ex,
after skip=10ex,
frame hidden,
overlay={%
\fill[yellow!10,rounded corners=3.14pt]
([yshift=2.5ex]frame.north west) rectangle ([yshift=-2.5ex]frame.south
east);
\draw[latex-latex,rounded corners=3.14pt] (frame.north west)
-- ++ (0,2.5ex) -| (frame.north east)
node[pos=0.06,fill=white,draw,rounded corners]{%
Example\refstepcounter{exnum} \theexnum};
\draw[latex-latex,rounded corners=3.14pt] (frame.south west)
-- ++ (0,-2.5ex) -| (frame.south east)
node[pos=0.44,fill=white,draw,rounded corners]{Example \theexnum};
}
}

\begin{document}
\begin{exbox}
It is not always true that
$\frac{\partial^2f}{\partial x\,\partial y}(a,b)= \frac{\partial^2f}{\partial y\,\partial x}(a,b)$
\end{exbox}
\begin{exbox}
I am another example
\end{exbox}
\end{document}


• if I wanted to fill the background with say yellow!10!white instead of white, it doesn't completely fill the frame, how can we alter the code to leave this possibility – MathScholar Jul 7 '19 at 14:30
• @MathScholar That's very easy. I added the fill. I only had to add \fill[yellow!10,rounded corners=3.14pt] ([yshift=2.5ex]frame.north west) rectangle ([yshift=-2.5ex]frame.south east);. (May I ask why you add this request if you decide to go with the other answer?) – user121799 Jul 7 '19 at 14:52
• thanks Marmot I have not been programming for awhile and I need alot of refreshing! – MathScholar Jul 7 '19 at 14:54
• I don't know why. Zarko did answer a few from the past and I did give yours the check. Both answers are great. I see you leaving/retiring. Thank you for all your help. Much appreciated! – MathScholar Jul 31 '19 at 22:08