所以我找到了问题像书中一样制作一个示例和阴影框符合我的愿望。
我修改了盒子和计数器以符合我的愿望。(第一个数字是章节,第二个数字是示例编号。这是按章节划分的吗?!)
%example Box
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{xcolor}
% EXAMPLES
%% set the counter for your environment
\newcounter{example}
\renewcommand{\theexample}{\thechapter.\arabic{example}}
%% set up the examplebox
\newmdenv[%
backgroundcolor=black!2,
linecolor=black,
outerlinewidth=1pt,
roundcorner=2mm,
skipabove=\baselineskip,
skipbelow=\baselineskip,
settings={\global\refstepcounter{example}},
frametitlefont={\bfseries Beispiel~\theexample\quad},
]{example}
简单使用如下:
\begin{example}[frametitle=Wie wird ein Ausführungsgraph erstellt]
select * from database where name='somename' and age>10
\end{example}
现在的问题是我如何获得一些示例列表,比如图片列表?此外,也许还有某种方式可以自动标记它?
答案1
您可以使用tocbasic
来自 KOMA-Script,如下所示:
\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}{%
backgroundcolor=black!2,
linecolor=black,
outerlinewidth=1pt,
roundcorner=2mm,
skipabove=\baselineskip,
skipbelow=\baselineskip,
}
%% setup the environments
\makeatletter
%%% with number
\newmdenv[%
style=example,
settings={%
\global\refstepcounter{example}
\addxcontentsline{loe}{example}[\theexample]{\mdf@frametitle}
},
frametitlefont={\bfseries Example~\theexample\quad},
]{example}
%%% without number (starred version)
\newmdenv[%
style=example,
%% uncomment the following three lines to get unnumberd examples in the list
% settings={%
% \addxcontentsline{loe}{example}{\mdf@frametitle}
% },
frametitlefont={\bfseries Example~\quad},
]{example*}
\makeatother
% LIST: loe = list of examples
% requieres tocbasic.sty which is loaded by scrreprt
%% setup new TOC
\addtotoclist{loe}
%% set command for headline
\newcommand{\listofloename}{List of Examples}
%% set up diplay in list like for figures
\makeatletter
\newcommand{\l@example}{\l@figure}
\makeatother
%% decalere new TOC
\setuptoc{loe}{chapteratlist}
%% own command to print list
\newcommand{\listofexamples}{\listoftoc{loe}}
% for testing
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\listofexamples
\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
\end{document}
我在代码中添加了一些注释...如果您对实现有更多疑问,请告诉我...