我无法找到一个示例,使用tcolorbox
它来设置框架标题下方线条的颜色和宽度,而不依赖于框架标题的背景颜色。可以通过和mdframed
来控制这些:frametitlerulecolor=red
frametitlerulewidth=4pt
使用时等效的选项有哪些tcolorbox
?
代码:
\documentclass{article}
\usepackage{xcolor}
\usepackage[tikz]{mdframed}
\usepackage{tcolorbox}
\mdfsetup{
roundcorner=4pt,
linewidth=1.5pt,
frametitlerule=true,
frametitlebackgroundcolor=olive!15,
% ----------------------------------
frametitlerulecolor=red,% How do I get the equivalent of two
frametitlerulewidth=4pt,% options when using {tcolorbox}?
}
\tcbset{
fonttitle=\bfseries,
coltitle=black,
colbacktitle=olive!15,
}
\begin{document}
\begin{mdframed}[backgroundcolor=green!25, frametitle={Mdframed}]
Content
\end{mdframed}
\begin{tcolorbox}[colback=green!25, title={Tcolorbox}]
Content
\end{tcolorbox}
\end{document}
答案1
要控制标题规则的线条粗细,可以使用选项titlerule=<length>
;不幸的是,在当前版本(编写此答案时为 3.36)中,没有单独控制标题规则颜色的键,并且此行将继承框架颜色;我相信托马斯会在新的更新中添加这个选项:)与此同时,您可以使用enhanced
和overlay
来单独控制属性;类似于以下内容:
\documentclass{article}
\usepackage{xcolor}
\usepackage[tikz]{mdframed}
\usepackage[many]{tcolorbox}
\mdfsetup{
roundcorner=4pt,
linewidth=1.5pt,
frametitlerule=true,
frametitlebackgroundcolor=olive!15,
% ----------------------------------
frametitlerulecolor=red,% How do I get the equivalent of two
frametitlerulewidth=4pt,% options when using {tcolorbox}?
}
\tcbset{
enhanced,
fonttitle=\bfseries,
coltitle=black,
colbacktitle=olive!15,
titlerule=0mm,
overlay={
\path[draw,red,line width=4pt] ([yshift=-2pt]title.south west) -- ([yshift=-2pt]title.south east);
}
}
\begin{document}
\begin{mdframed}[backgroundcolor=green!25, frametitle={Mdframed}]
Content
\end{mdframed}
\begin{tcolorbox}[colback=green!25, title={Tcolorbox}]
Content
\end{tcolorbox}
\end{document}
输出:
答案2
我把 Gonzalo 的建议视为功能请求 :-)
在tcolorbox
版本中3.40 (2015/01/14)
,有一个新的键titlerule style
可以设置标题规则的颜色(或其他样式选项):
\documentclass{article}
\usepackage{xcolor}
\usepackage[tikz]{mdframed}
\usepackage[many]{tcolorbox}
\mdfsetup{
roundcorner=4pt,
linewidth=1.5pt,
frametitlerule=true,
frametitlebackgroundcolor=olive!15,
% ----------------------------------
frametitlerulecolor=red,% How do I get the equivalent of two
frametitlerulewidth=4pt,% options when using {tcolorbox}?
}
\tcbset{
enhanced,
fonttitle=\bfseries,
coltitle=black,
colbacktitle=olive!15,
% ----------------------------------
toptitle=1mm,bottomtitle=1mm,% fill in some more 'air' into the title
titlerule style=red,
titlerule=4pt,
}
\begin{document}
\begin{mdframed}[backgroundcolor=green!25, frametitle={Mdframed}]
Content
\end{mdframed}
\begin{tcolorbox}[colback=green!25, title={Tcolorbox}]
Content
\end{tcolorbox}
\end{document}
文档中的更多示例: