20

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}
3
  • 1
    Welcome to TeX.sx! I think it would be better if you split your question in two because this site works best if you ask one question at the time. Also please provide screenshots of the entities you want to produce.
    – N.N.
    Dec 15, 2011 at 7:28
  • 1
    In my eyes these both questions are ok for on post … I added an example as answer but in the future it would be good if you try it yourself first an then post your code. Otherwise it looks like „I need XXX build it for me!” which is not relay nice ;-) Furthermore a better title is recommended, like “Framed boxes width round corners or tile on the frame” …
    – Tobi
    Dec 15, 2011 at 8:19
  • Is the source code for this book available somewhere?
    – Village
    Dec 15, 2011 at 22:56

4 Answers 4

17

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 …

3
  • Any way to get some kind of table of examples with this too? That would be insane!
    – BennX
    Aug 23, 2015 at 14:57
  • @BennX: Sure … one can setup a new list for the examples. If you make a new (follow-up) question and link it here I’ll show you how. I don’t want to add it here to keep the code clean …
    – Tobi
    Aug 24, 2015 at 13:31
  • Wrote the question. Thanks for your help: tex.stackexchange.com/questions/262915/…
    – BennX
    Aug 24, 2015 at 13:48
10

TIKZ MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage[english]{babel}
\usepackage{blindtext}
\newcommand{\mybox}[2]{%
         \begin{center}%
            \begin{tikzpicture}%
                \node[rectangle, draw=#2, top color=#2!10, bottom color=#2!90, rounded corners=5pt, inner xsep=5pt, inner ysep=6pt, outer ysep=10pt]{
                \begin{minipage}{0.75\linewidth}#1\end{minipage}};%
            \end{tikzpicture}%
         \end{center}%
}
\begin{document}
\blindtext
\mybox{\blindtext}{green}
\blindtext
\mybox{\blindtext}{red}
\end{document}

enter image description here

2
  • @Marco Daniel how can we change the colour at the very next paragraph? I mean i want to have a green backround here and a pink after that. How can we do this possible??
    – Giannis
    Mar 13, 2014 at 21:17
  • @Giannis I updated the code with your request. Mar 21, 2014 at 9:18
3

This partially answers your first question:

\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}}

It's not difficult to change the font in the heading.

3

We can use the package tcolorbox by Thomas F. Sturm.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .