我想为自定义tcolorbox
环境实现一个选项键,当我将其包含在可选参数中时,它会扩展为类似的内容underlay = {<tikz code>}
。
在下面的代码中,我想underlay = {...}
用一个简单的键替换quotation
。我的目标是像这样重现第二个框:\begin{sigbox}[quotation]
\documentclass[11pt]{scrreprt}
\usepackage{lipsum}
\usepackage[skins]{tcolorbox}
%
%
\newtcolorbox{sigbox}[1][]{%
enhanced, remember, colback=yellow!25!white, arc=0pt, boxrule=0pt, leftrule=3 ex %
, colframe=yellow!85!red!33!white %
, underlay = {%
\path[fill=yellow!25!white] (frame.south west) -- ([yshift=3 ex]frame.south west) --
([xshift = 1.5 ex ,yshift=1.5 ex]frame.south west) -- ([xshift = 3 ex , %
yshift = 3 ex]frame.south west) -- ([xshift = 3 ex]frame.south west) -- cycle;
}%
, overlay = {%
\path ([xshift=1.5 ex, yshift = -2.25 ex]frame.north west) node %
{\textcolor{tcbcolback!33!white}{\LARGE\textbf{!}}};%
}%
,#1 %
}%
%
\begin{document}
%
\begin{sigbox}
\lipsum[7]
\end{sigbox}
%
\begin{sigbox}[%
underlay = {%
\path ([xshift=1.5 ex, yshift = -5.5 ex]frame.north west) node %
{\textcolor{tcbcolback!33!white}{\LARGE\textbf{"}}};%
}%
]%
\lipsum[8]
\end{sigbox}
%
\end{document}
我是否应该仅创建一个宏 ala \newcommand{\quotation}{underlay = {<tikz code>}}
;我可以使用例如一些条件表达式来实现它吗xstring
;或者我必须学习如何pgfkeys
工作?
答案1
我认为您正在寻找的是\tcbset
可以帮助您创建自定义样式的东西(我稍微简化了代码):
\documentclass[11pt]{scrreprt}
\usepackage{lipsum}
\usepackage[skins]{tcolorbox}
\tcbset{
quotation/.style={
overlay = {
\node[text=tcbcolback!33!white, font=\LARGE\bfseries] at
([xshift=1.5ex, yshift=-2.25ex]frame.north west) {"};
}
}
}
\newtcolorbox{sigbox}[1][]{
enhanced, remember, colback=yellow!25!white, arc=0pt, boxrule=0pt, leftrule=3ex, colframe=yellow!85!red!33!white,
underlay = {
\path[fill=yellow!25!white] (frame.south west) --
([yshift=3ex]frame.south west) --
([xshift=1.5ex, yshift=1.5ex]frame.south west) --
([xshift=3ex, yshift=3ex]frame.south west) --
([xshift=3ex]frame.south west) -- cycle;
},
overlay = {
\node[text=tcbcolback!33!white, font=\LARGE\bfseries] at
([xshift=1.5ex, yshift=-2.25ex]frame.north west) {!};
},
#1
}
\begin{document}
\begin{sigbox}
\lipsum[2]
\end{sigbox}
\begin{sigbox}[quotation]
\lipsum[2]
\end{sigbox}
\end{document}
当然,您应该始终小心,不要覆盖现有的样式。