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

enter image description here

So far I have skeleton:





\newcommand{\Example}[1]{\begin{tikzpicture} \stepcounter{exnum}
   \node [mybox1] (box){%
 \node[fancytitle1, right=10pt] at (box.north west) {Example 

  % 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]


This produces:

enter image description here

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


Like this?

enter image description here

\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,
\node (ex) [exercise] {#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);
    \medskip\par}% end new command



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.

    before skip=10ex,
    after skip=10ex,
    frame hidden,
    \fill[yellow!10,rounded corners=3.14pt]
     ([yshift=2.5ex]frame.north west) rectangle ([yshift=-2.5ex]frame.south
            \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};

       It is not always true that
       \[ \frac{\partial^2f}{\partial x\,\partial y}(a,b)=
       \frac{\partial^2f}{\partial y\,\partial x}(a,b)\]
       I am another example

enter image description here

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.