[Tex/LaTex] Make an Example and shaded box like in the book

boxesexamples

I want to make Examples in the book as in the following book

http://www.analogmachine.org/Books/Chapter1.pdf

See Page 2…

Also shaded box as in the page 3… Pictures can be seen below.

Shaded Box 1

Shaded Box 2


Minimal Code for the First part of the Question.

\documentclass{book}

\usepackage{amsthm,color}
\theoremstyle{definition}
\newtheorem{exinn}{Example}[chapter]
\newenvironment{example}
  {\clubpenalty=10000
   \begin{exinn}%
   \mbox{}%
   {\color{blue}\leaders\hrule height .8ex depth \dimexpr-.8ex+0.8pt\relax\hfill}%
   \mbox{}\linebreak\ignorespaces}
  {\par\kern2ex\hrule\end{exinn}}

\begin{document}
\chapter{Chapter One}
\section{Section One}

\begin{example}
    What is $a^2 - b^2$?

$a^2 - b^2 = (a - b) \times (a + b)$
\end{example}

\end{document}

Best Answer

Update
I included @Marco’s code (setting the title with frametitlefont to be able to add an extra headline to each environment) and implemented an unnumbered version for examples (example*)

Have a look at the mdframed package.

\documentclass{scrartcl}

\usepackage[framemethod=TikZ]{mdframed}
\usepackage{xcolor}

% EXAMPLES
%% set the counter for your environment
\newcounter{example}
\renewcommand{\theexample}{\thesection.\arabic{example}}

%% define the style
\mdfdefinestyle{example}{%
    linecolor=blue,
    outerlinewidth=2pt,
    bottomline=false,
    leftline=false,rightline=false,
    skipabove=\baselineskip,
    skipbelow=\baselineskip,
    frametitle=\mbox{},
}
%% setup the environments
%%% with number
\newmdenv[%
    style=example,
    settings={\global\refstepcounter{example}},
    frametitlefont={\bfseries Example~\theexample\quad},
]{example}
%%% without number (starred version)
\newmdenv[%
    style=example,
    frametitlefont={\bfseries Example~\quad},
]{example*}

% BOXES
%% set up the environment
\newmdenv[%
    backgroundcolor=red!8,
    linecolor=red,
    outerlinewidth=1pt,
    roundcorner=5mm,
    skipabove=\baselineskip,
    skipbelow=\baselineskip,
]{boxed}

% for testing
\usepackage[english]{babel}
\usepackage{blindtext}

\begin{document}
\section{Section One}
\blindtext
\begin{example}[frametitle=Some Headlinetext]
    \blindtext
\end{example}
\blindtext
\begin{example*}[frametitle=Foobar baz]
    \blindtext
\end{example*}
\blindtext
\begin{example}
    \blindtext
\end{example}
\blindtext
\begin{boxed}
    \blindtext
\end{boxed}
\blindtext
\end{document}

result

The manual shows an example putting the title on the frame …

Related Question