是否可以在 tcolorbox 中添加双边框?实际上,我正在尝试使用 titlesec 和 tcolorbox 设计一个有两个边框的章节。内边框颜色将为白色(与页面颜色相同),外边框颜色将为青色(与框背景颜色相同),类似于此。
这是我正在尝试的代码:
\usepackage[explicit]{titlesec}
\usepackage[many]{tcolorbox}
\definecolor{myCyan}{HTML}{13C39D}
\titleformat{\chapter}[display]
{\sffamily\bfseries\Huge\filcenter}
{}
{0pt}
{%
\begin{tcolorbox}[
enhanced,
colback = myCyan,
fontupper=\color{white},
boxrule=0pt,
colframe=black!70!white,
arc=0pt,
outer arc=0pt,
top=20pt,
bottom=20pt,
left=20pt,
right=20pt,
]
\begin{center}
#1
\end{center}
\end{tcolorbox}%
}
\titlespacing*{\chapter}{0pt}{0cm}{0cm}
答案1
这可能是个开始。想法是嵌套tcolorbox
es。
\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}[
colback=green!50!blue,
colframe=green!50!blue,
left=1.5pt,right=1.5pt,top=1.5pt,bottom=-1.5pt,
sharp corners,
boxsep=0pt
]
\begin{tcolorbox}[
colback=green!50!blue,
colframe=white,
leftrule=1.5pt,rightrule=1.5pt,toprule=1.5pt,bottomrule=1.5pt,
sharp corners,
fontupper=\color{white}\sffamily\bfseries\Large\centering
]
Android tutorial
\end{tcolorbox}%
\end{tcolorbox}
\end{document}
现在让我们用它来定制我们的章节。
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage[many]{tcolorbox}
\definecolor{myCyan}{HTML}{13C39D}
\titleformat{\chapter}[display]
{\sffamily\bfseries\Huge\filcenter}
{}
{0pt}
{%
\begin{tcolorbox}[
colback=myCyan,
colframe=myCyan,
left=1.5pt,right=1.5pt,top=1.5pt,bottom=-1.5pt,
sharp corners,
boxsep=0pt
]
\begin{tcolorbox}[
colback=myCyan,
colframe=white,
leftrule=1.5pt,rightrule=1.5pt,toprule=1.5pt,bottomrule=1.5pt,
sharp corners,
fontupper=\color{white}\sffamily\bfseries\Huge\centering
]
\thechapter. #1
\end{tcolorbox}%
\end{tcolorbox}%
}
\titlespacing*{\chapter}{0pt}{0cm}{0cm}
\usepackage{lipsum}
\begin{document}
\chapter{Lorem lipsum}
\lipsum[1]
\end{document}
答案2
没有必要嵌套tcolorboxes
,您可以使用enhanced
带有附加的框borderline
:
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage[many]{tcolorbox}
\definecolor{myCyan}{HTML}{13C39D}
\titleformat{\chapter}[display]
{\sffamily\bfseries\Huge\filcenter}
{}
{0pt}
{%
\begin{tcolorbox}[
enhanced,
colback=myCyan,
colframe=myCyan,
boxsep=5pt,
sharp corners,
borderline={1.5pt}{3pt}{white},
colupper=white,
fontupper=\sffamily\bfseries\Huge,
halign upper=center
]
\thechapter. #1
\end{tcolorbox}%
}
\titlespacing*{\chapter}{0pt}{0cm}{0cm}
\usepackage{lipsum}
\begin{document}
\chapter{Lorem lipsum}
\lipsum[1]
\end{document}