刚看文档抄的... maybe related link by 鱼老师
\documentclass[a4paper,twoside,12pt,openany]{ctexbook}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\definecolor{tianyi}{HTML}{66CCFF}
\definecolor{yanhe}{HTML}{00FFCC}
\definecolor{ling}{HTML}{EE0000}
\definecolor{qingxian}{HTML}{FFFF00}
\definecolor{skyblue}{HTML}{aeeafa}
\definecolor{darkblue}{RGB}{60,0,180}
% math typesetting
\usepackage{amsmath,amsthm,amssymb}
\usepackage{lipsum,zhlipsum}
\begin{document}
\NewTColorBox[auto counter,number within=chapter]{mytcbbox}{O{black}m}{
enhanced jigsaw,breakable,colframe=#1,top=2ex,boxrule=2pt,toprule=0pt,fonttitle=\large\bfseries,colback=white,sharp corners,attach boxed title to top left={xshift=3em,yshift=-\tcboxedtitleheight/2},coltitle=#1,title={Definition\thetcbcounter~#2},
boxed title style={%
empty,left=1pt,right=1pt,bottom=0pt,sharp corners,
overlay={%
\draw[color=#1,line width=2pt,line cap=round]
([yshift=-1pt]frame.west)--
++(-2.9em,0) ([yshift=-1pt]frame.east)--
++(3em,0);
}
},
}
\chapter{chap1}
\begin{mytcbbox}{My Def Title}
\lipsum[2]
\end{mytcbbox}
\begin{mytcbbox}[qingxian]{My Def Title}
\lipsum[1]
\end{mytcbbox}
\begin{mytcbbox}[tianyi]{My Def Title}
I can eat the glass band it doesn't hurt me. I can eat the glass band it doesn't hurt me. I can eat the glass band it doesn't hurt me.
\end{mytcbbox}
\chapter{chap2}
\begin{mytcbbox}[yanhe]{My Def Title}
我能吞下玻璃而不伤身体. 我能吞下玻璃而不伤身体. 我能吞下玻璃而不伤身体. 我能吞下玻璃而不伤身体. 我能吞下玻璃而不伤身体. 我能吞下玻璃而不伤身体.
\end{mytcbbox}
\begin{mytcbbox}[darkblue]{My Def Title}
\zhlipsum[2]
\end{mytcbbox}
\begin{mytcbbox}[skyblue]{My Def Title}
\zhlipsum[name=zhufu]
\end{mytcbbox}
\end{document}
Note:
- 懂得使用md代码块,这非常好(!)
- 题目还可以改进,需要体现这个样式的特征,例如『实现boxrule断开样式』而不是泛泛的『实现某种特定的边框』,好的题目可以让本post更容易被需要的人搜到
3.
上边框仅绘制两端长度为 3 em (可调整)的部分
因为一些原因,我不想暴露出控制这个长度的接口,如果确有需要修改,你可以自行试试修改以下绘制横线的长度(-2.9em
和3em
):
overlay={%
\draw[color=#1,line width=2pt,line cap=round]
([yshift=-1pt]frame.west)--++(-2.9em,0)
([yshift=-1pt]frame.east)--++(3em,0);
}
问 tcolorbox 实现某种特定的边框