在网上看到了一个这样的盒子形状,不知是tikz画的还是tcolorbox宏包定制的,搜了网上好久,没有发现类似的解决方法.
tcolorbox宏包说明书也找了,只找到了boxed-矩形的,其它类形的没有找到.例如说菱形的,椭圆的.
\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
\def\pgfgetnodeheight(#1)#2{
\path ($(#1.south) - (#1.north)$);
\pgfmathsetmacro#2{veclen(\pgf@x, \pgf@y)}
\edef#2{#2pt}
}
\def\pgfgetnodewidth(#1)#2{
\path ($(#1.east) - (#1.west)$);
\pgfmathsetmacro#2{veclen(\pgf@x, \pgf@y)}
\edef#2{#2pt}
}
\makeatother
\definecolor{tcbline}{RGB}{23, 139, 23}
\NewDocumentEnvironment{mybox}{O{}+b}{%
\begin{tcolorbox}[
breakable,
enhanced,
colbacktitle = white,
coltitle = black,
colback = white,
colframe = tcbline,
boxrule = 1pt,
arc = 0pt,
top = 2ex,
attach boxed title to top left =
{
xshift = 2em,
yshift=-\tcboxedtitleheight/2,
yshifttext=2mm-\tcboxedtitleheight/2
},
boxed title style =
{
frame code =
{
\pgfgetnodeheight(frame)\nHeight
\pgfgetnodewidth(frame)\nWidth
\draw[tcbline, thick] (frame.center) ellipse[x radius = \nWidth/2 - .1cm, y radius = \nHeight/2 + .1cm];
},
interior code =
{
\pgfgetnodeheight(interior)\nHeight
\pgfgetnodewidth(interior)\nWidth
\fill[tcb fill interior] (interior.center) ellipse[x radius = \nWidth/2 - .07cm, y radius = \nHeight/2];
}
},
#1
]
#2
\end{tcolorbox}
}{}
\begin{document}
\begin{mybox}[title = Example]
\begin{center}
Content
\end{center}
\end{mybox}
\end{document}
\documentclass[UTF8]{ctexbook}
\usepackage{titletoc}%toc:table of content
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{pagecolor}
\usepackage{layout}%布局
\usepackage{multicol}%多栏排版宏包
\usepackage{geometry}%布局宏包
\usepackage{hyperref}%引入 hyperref 宏包以支持超链接
\usepackage{nameref}
\usepackage{tikz}
\usepackage{lipsum} % 用于生成示例文本
\pgfdeclarelayer{diyituceng}
\pgfdeclarelayer{diertuceng}
\pgfsetlayers{diyituceng,main,diertuceng}
%In pgf layers are referenced using names. The standard layer, which is a bit special in certain ways, is called main. If nothing else is specified, all graphic commands are added to the main layer. You can declare a new layer using the following command:
\usetikzlibrary{shapes.geometric}
\newcommand{\tuoyvan}[1]{%椭圆
\begin{pgfonlayer}{diertuceng}
\node[ellipse, draw, fill=white, inner sep=2pt, anchor=center] (ellipse) at (0,0) {#1};
\end{pgfonlayer}
}%
\newcommand{\jvxing}[1]{%矩形
\begin{pgfonlayer}{diyituceng}
\node[anchor=north west, text width=\linewidth, align=center, fill=white, draw] (title) at ([xshift=-30pt]ellipse.center) {#1};
\end{pgfonlayer}
}%
%椭圆镶嵌矩形
\titleformat{\section}[block]%
{\normalfont\Large\bfseries\begin{tikzpicture}[baseline=(ellipse.base)]}%
{\tuoyvan{\thesection}}%
{0pt}%
{\jvxing}%
[\end{tikzpicture}]%
%before-code
%after-code
%\titleformat{command}[shape]{format}{label}{sep}{before}[after]
\begin{document}
\section{第一节}
\end{document}
完美
tikz
@u19850 非常棒!再次感谢!