我在用着彩色盒子包来绘制彩色框。设置选项后,\tcbset {opt1, opt2}
我只想重置opt1
为默认值。经过它的文档,我找不到重置选项的方法。
这就是我想要实现的目标。
\documentclass{article}
\usepackage[most]{tcolorbox}
% set some option using tcbset
\tcbset { frame hidden, attach title to upper,coltitle=red, colframe=red }
\newtcolorbox[]{noframebox}[1][] { #1 }
% Following code resets everything back to package defaults
% I just want to make frame visible
\newtcolorbox[]{framedbox}[1][] { reset, #1}
\begin{document}
\begin{noframebox}[title=No frame:~]
So far so good.
\end{noframebox}
\begin{framedbox}[title=Framed:~]
% This must be in frame and title must be attached to frame.
Every style option is reset for framedbox.
\end{framedbox}
\end{document}
答案1
tcolorbox
使用pgfkeys
它的 key=value 接口。您只需在其中定义自己的样式,然后在不同的框中重复使用该样式即可。无需重复代码(除了指定样式):
\documentclass{article}
\usepackage[most]{tcolorbox}
% set some option using tcbset
\tcbset{aravind/.style={attach title to upper,coltitle=red, colframe=red}}
\newtcolorbox[]{noframebox}[1][] {enhanced,frame hidden,aravind,#1}
% Following code resets everything back to package defaults
% I just want to make frame visible
\newtcolorbox[]{framedbox}[1][]{aravind,#1}
\begin{document}
\begin{noframebox}[title=No frame:~]
So far so good.
\end{noframebox}
\begin{framedbox}[title=Framed:~]
% This must be in frame and title must be attached to frame.
Every style option is reset for framedbox.
\end{framedbox}
\end{document}
另一种方法,在我看来不那么优雅,可以是手动设置frame style
选项来删除效果(这也frame hidden
可以撤消任何其他键改变的效果)frame style
\documentclass{article}
\usepackage[most]{tcolorbox}
% set some option using tcbset
\tcbset { enhanced,frame hidden, attach title to upper,coltitle=red, colframe=red }
\newtcolorbox[]{noframebox}[1][] {#1}
% Following code resets everything back to package defaults
% I just want to make frame visible
\newtcolorbox[]{framedbox}[1][] {frame style={}, #1}
\begin{document}
\begin{noframebox}[title=No frame:~]
So far so good.
\end{noframebox}
\begin{framedbox}[title=Framed:~]
% This must be in frame and title must be attached to frame.
Every style option is reset for framedbox.
\end{framedbox}
\end{document}
两种代码变体的输出: