我正在尝试tcolorbox
使用自定义代码来绘制它的框架但访问存储在的颜色colframe
。
到目前为止我已经尝试过
\newtcolorbox{leftborderbox}[1][]{
enhanced,
breakable,
colframe=orange,
colback=orange!20,
frame code={
\fill[fill=\pgfkeysvalueof{/tcb/colframe}] (frame.south west) -- (interior.south west) -- (interior.north west) -- (frame.north west);
},
sharp corners,
boxsep=0pt,
left=5pt,
right=5pt,
top=6pt,
bottom=6pt,
boxrule=0pt,
leftrule=4pt,
#1
}
\begin{leftborderbox}[colframe=pink]
Hi There!
\end{leftborderbox}
但我收到一个错误,提示\pgfkeysvalueof{/tcb/colframe}
不是颜色。我如何访问此键的值?
答案1
选项中指定的某些颜色tcolorbox
带有前缀tcbcol@
,例如
tcbcol@frame
框架的颜色tcbcol@title
-- 标题文字颜色tcbcol@back
- 背景色tcbcol@upper
-- 上方框文字颜色tcbcol@lower
-- 下方框文字颜色tcbcol@backtitle
-- 标题的背景颜色
在默认\tcbset
设置中,tcolorbox.sty
这些tcbcol@...
实际上是.colorlet:
\tcbset{... % excerpt from tcolorbox.sty
colback/.colorlet=tcbcol@back,
colframe/.colorlet=tcbcol@frame,
colupper/.colorlet=tcbcol@upper,
collower/.colorlet=tcbcol@lower,
coltext/.style={colupper=#1,collower=#1},
coltitle/.colorlet=tcbcol@title,
...
}
\documentclass{article}
\usepackage[most]{tcolorbox}
\newtcolorbox{leftborderbox}[1][]{
enhanced,
breakable,
colframe=orange,
colback=orange!20,
frame code={
\fill[fill=tcbcol@frame] (frame.south west) -- (interior.south west) -- (interior.north west) -- (frame.north west);
\draw (0,0) node {};
},
sharp corners,
boxsep=0pt,
left=5pt,
right=5pt,
top=6pt,
bottom=6pt,
boxrule=0pt,
leftrule=4pt,
#1
}
\begin{document}
\begin{leftborderbox}[colframe=pink]
Hi There!
\end{leftborderbox}
\end{document}