![如何通过 tcolorbox 更新定理并格式化如下?](https://linux22.com/image/408709/%E5%A6%82%E4%BD%95%E9%80%9A%E8%BF%87%20tcolorbox%20%E6%9B%B4%E6%96%B0%E5%AE%9A%E7%90%86%E5%B9%B6%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%A6%82%E4%B8%8B%EF%BC%9F.png)
我的代码
\documentclass[12pt,a4paper,oneside]{book}
\usepackage{amsmath}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
%%%%%%%%
\newtheorem{ex}{Example}
%%%%%%%%
\AtBeginEnvironment{ex}{
\begin{tcolorbox}[colframe=black,colback=blue!10,breakable,boxrule=0.5pt,sharp corners]
}
\AtEndEnvironment{ex}{
\end{tcolorbox}
}
\begin{document}
\begin{ex}
\lipsum[1]
\end{ex}
\begin{ex}
\lipsum[2]
\end{ex}
\begin{tcolorbox}[enhanced,title=Example 1,
colframe=blue!50!black,colback=blue!10!white,colbacktitle=blue!5!yellow!10!white,
fonttitle=\bfseries,coltitle=black,attach boxed title to top center=
{yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={boxrule=0.5mm,
frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)
-- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
-- (frame.south east) -- (frame.south west) -- cycle; },
interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
-- (interior.north west) -- (interior.north east)
-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
-- cycle;} }]
\lipsum[1]
\end{tcolorbox}
\end{document}
答案1
您可以newtcbtheorem
像以下代码一样声明环境。有关此命令的更多信息,请参阅文档theorem
中的部分tcolorbox
或更新部分这个答案
\documentclass[12pt,a4paper,oneside]{book}
\usepackage{amsmath}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\newtcbtheorem[number within=chapter]{ex}{Example}{%
enhanced,
colframe=blue!50!black, colback=blue!10!white, colbacktitle=blue!5!yellow!10!white,
fonttitle=\bfseries, coltitle=black,
attach boxed title to top center = {%
yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={boxrule=0.5mm,
frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)
-- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
-- (frame.south east) -- (frame.south west) -- cycle; },
interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
-- (interior.north west) -- (interior.north east)
-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
-- cycle;}}
}{ex}
\begin{document}
\begin{ex}{A nice example}{1}
\lipsum[1]
\end{ex}
\begin{ex}{}{}
As you can see in theorem~\ref{ex:1}
\lipsum[2]
\end{ex}
\end{document}