我想创建一个\newtcolorbox
具有多个选项和自动计数器的高级功能,但无法使其工作......
MWE 是:
\documentclass[11pt,a4paper]{article}
\usepackage{lmodern}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newtcolorbox {mybox4}[2][]
{
enhanced,
colback=white,
colframe=red!65!black,
enlarge top by=10mm,
overlay={%
\path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
\node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{
\textbf{\sffamily #1}}};
\path[fill=red!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
\node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \themycounter}}};
\node at ([shift={(18mm,4mm)}]n2){
\itshape\textbf{\sffamily #2}};
}}
\newcounter{mycounter}
%----------------------------------------------------------------------------------------
%TCOLORBOXES
%----------------------------------------------------------------------------------------
\begin{document}
\begin{mybox4}{sample}{Solution}
{step=mycounter,label=\themycounter}
This is a \textbf{tcolorbox}.\par
a lot of text here ... This is Example \ref{one}
\tcblower
some text
\end{mybox4}
\end{document}
提前谢谢 A
答案1
除非使用\NewTColorBox
宏,否则语法\newtcolorbox
是
\newtcolorbox[init options]{boxname}[number of args][default opt arg]{option}
。
根据请求,初始化选项可以是auto counter
或。use counter
这里应该使用可选参数来改变框的默认设置,通常在选项末尾用 来指定#1
。
该step
选项实际上不再是必要的(“引用”tcolorbox
手册第 98 页):
\documentclass[11pt,a4paper]{article}
\usepackage{lmodern}
\usepackage[skins]{tcolorbox}
\newtcolorbox[auto counter]{mybox4}[3][]{
enhanced,
colback=white,
colframe=red!65!black,
enlarge top by=10mm,
overlay={%
\path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
\node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{
\textbf{\sffamily #2}}};
\path[fill=red!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
\node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \thetcbcounter}}};
\node at ([shift={(18mm,4mm)}]n2){
\itshape\textbf{\sffamily #3}};
},
#1
}
\newcounter{mycounter}
%----------------------------------------------------------------------------------------
%TCOLORBOXES
%----------------------------------------------------------------------------------------
\begin{document}
\begin{mybox4}[label=one]{sample}{Solution}
This is a \textbf{tcolorbox}.\par
a lot of text here ... This is Example \ref{one}
\tcblower
some text
\end{mybox4}
\end{document}