我想在书中举例说明如下
http://www.analogmachine.org/Books/Chapter1.pdf
见第 2 页...
还有像第 3 页那样的阴影框...图片如下所示。
问题第一部分的最少代码。
\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}
答案1
更新
我包含了@Marco 的代码(设置标题以便frametitlefont
能够为每个环境添加额外的标题)并实现了一个未编号的版本作为示例(example*
)
看看mdframed
包裹。
\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}
手册展示了将标题放在框架上的示例……
答案2
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}
答案3
这部分回答了您的第一个问题:
\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}}
更改标题的字体并不难。
答案4
我们可以使用包tcolorbox
作者:Thomas F. Sturm。