答案1
- 设置
attach boxed title to top left
为在左上角有一个盒装标题。 - 标题之上的规则和自定义标题框被吸引
boxed title style={overlay={...}}
- 框架上方的规则和标题下方有阴影被吸引
overlay unbroken={...}
- 左规则绘制于
borderline west=...
- 阴影受控制
drop fuzzy shadow
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\tcbuselibrary{skins}
\usetikzlibrary{shadings}
\newcounter{example}
\colorlet{colexam}{red!75!black}
\tcbset{
base/.style={
empty,
frame engine=path,
colframe=yellow!10,
sharp corners,
title={Example \thetcbcounter},
attach boxed title to top left={yshift*=-\tcboxedtitleheight},
boxed title style={size=minimal, top=4pt, left=4pt},
coltitle=colexam,fonttitle=\large\bfseries\sffamily,
}
}
\newtcolorbox[use counter=example]{myexamplea}{%
base,
boxed title style={overlay={
\draw[colexam,line width=3pt,] (frame.north west)--(frame.north east);
}},
colback=colexam,
overlay unbroken={
\draw[colexam] ([yshift=-1.5pt]title.north east)--([xshift=-0.5pt, yshift=-1.5pt]title.north-|frame.east);
},
}
\newtcolorbox[use counter=example]{myexampleb}{%
base,
drop fuzzy shadow,
borderline west={3pt}{-3pt}{colexam},
}
\newtcolorbox[use counter=example]{myexamplec}{%
base,
drop fuzzy shadow,
coltitle=black,
borderline west={3pt}{-3pt}{teal!50},
attach boxed title to top left={xshift=-3mm, yshift*=-\tcboxedtitleheight/2},
boxed title style={right=3pt, bottom=3pt, overlay={
\draw[draw=teal!70, fill=teal!70, line join=round]
(frame.south west) -- (frame.north west) -- (frame.north east) --
(frame.south east) -- ++(-2pt, 0) -- ++(-2pt, -4pt) --
++(-2pt, 4pt) -- cycle;
}},
overlay unbroken={
\scoped \shade[left color=teal!10!black, right color=teal]
([yshift=-0.2pt]title.south west) -- ([xshift=-1.5pt, yshift=-0.2pt]title.south-|frame.west) -- ++(0, -6pt) -- cycle;
},
}
\begin{document}
\begin{myexamplea}
\lipsum[1][1-3]
\end{myexamplea}
\begin{myexampleb}
\lipsum[1][1-3]
\end{myexampleb}
\begin{myexamplec}
\lipsum[1][1-3]
\end{myexamplec}
\end{document}
答案2
直接来自书中——http://mirror.iopb.res.in/tex-archive/macros/latex/contrib/tcolorbox/tcolorbox.pdf
\documentclass[11pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{varioref}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{cleveref}
\newtcolorbox{YetAnotherTheorem}[1]%
{enhanced,arc=0mm,outer arc=0mm,
boxrule=0mm,toprule=1mm,bottomrule=1mm,left=1mm,right=1mm,
titlerule=0mm,toptitle=0mm,bottomtitle=0mm,top=0mm,
colframe=red!50!black,colback=red!5!white,coltitle=red!50!black,
colbacktitle=yellow!50!white,colback=red!5!white,
title=#1,
fonttitle=\bfseries\sffamily\normalsize,fontupper=\normalsize\itshape,
}
\begin{document}
\begin{YetAnotherTheorem}{Mittelwertsatz f\"{u}r $\mathbf{n}$ Variable}
$f\in C^{1}(D,\mathbb{R})$. Dann gibt es auf jeder Strecke
$[x_0,x]\subset D$ einen Punkt $\xi\in[x_0,x]$, so dass gilt
\begin{equation*}
f(x)-f(x_0) = \operatorname{grad} f(\xi)^{\top}(x-x_0)
\end{equation*}
\end{YetAnotherTheorem}
\end{document}
编辑
尝试各种选项——
{enhanced,arc=1mm,outer arc=1mm,
boxrule=0mm,toprule=0mm,bottomrule=0mm,left=1mm,right=1mm,leftrule=2pt,
titlerule=0mm,toptitle=0mm,bottomtitle=0mm,top=0mm,
colframe=blue!50!black,colback=blue!5!white,coltitle=blue!50!black,
colbacktitle=yellow!50!white,colback=green!5!white,
title=#1,
fonttitle=\bfseries\sffamily\normalsize,fontupper=\normalsize\itshape,
}
--将产生不同的结果,如下所示
编辑标题框--再次改变选项
{
enhanced,
arc=1mm,
outer arc=1mm,
boxrule=0mm,
toprule=0mm,
bottomrule=0mm,
left=1mm,
right=1mm,
leftrule=2pt,
titlerule=0mm,
toptitle=0mm,
bottomtitle=0mm,
top=0mm,
colframe=blue!50!black,
colback=blue!5!white,
title=#1,
fonttitle=\bfseries\sffamily\normalsize,fontupper=\normalsize\itshape,
attach boxed title to top left={
xshift=-1mm,
yshift=-5mm,
yshifttext=-1mm
},
top=1.5em,
boxed title style={
sharp corners,
size=small,
colback=blue!75!black,
colframe=blue!75!black,colbacktitle=white
}
}