有不少国外的书籍在制作上都是比较花心思的,比如做一个好看的章节样式,比较清晰的序号环境,定义定理等等,今天这个环境就是别人设计好的example环境还是非常不错,有需要用到的可以拿来主义。
- \documentclass{article}
- \usepackage{lipsum}
- \usepackage[many]{tcolorbox}
- \definecolor{greentitle}{RGB}{61,170,61}
- \definecolor{greentitleback}{RGB}{216,233,213}
- \newtcolorbox[
- auto counter,
- number within=section
- ]{myexample}[2][]{%
- breakable,
- enhanced,
- colback=white,
- colbacktitle=white,
- arc=0pt,
- leftrule=1pt,
- rightrule=0pt,
- toprule=0pt,
- bottomrule=0pt,
- titlerule=0pt,
- colframe=greentitleback,
- fonttitle=\normalcolor,
- overlay={
- \node[
- outer sep=0pt,
- anchor=east,
- text width=2.5cm,
- minimum height=4ex,
- fill=greentitleback,
- font=\color{greentitle}\sffamily\scshape
- ] at (title.west) {example~\thetcbcounter};
- },
- title=#2,
- #1
- }
- \newcommand\Solution{\par\textbf{\textsf{Solution}}\par\medskip}
- \begin{document}
- \section{A test section}
- \begin{myexample}{Factorise $x^2-2x+1$}
- \Solution
- \lipsum[4]
- \end{myexample}
- \end{document}