怎么用tcolorbox 宏包制作含有ellipsoid形状标题盒子

发布于 2024-08-11 22:44:05

在网上看到了一个这样的盒子形状,不知是tikz画的还是tcolorbox宏包定制的,搜了网上好久,没有发现类似的解决方法.
5e9b48123.png
tcolorbox宏包说明书也找了,只找到了boxed-矩形的,其它类形的没有找到.例如说菱形的,椭圆的.

查看更多

关注者
0
被浏览
649
鱼香肉丝没有鱼先生
脾气不好,别来惹我!!!
\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}

image.png

3 个回答
latex2020
latex2020 2024-08-12
这家伙很懒,什么也没写!

感谢您的回答,latex的学习需要时间沉淀.

.
. 2024-08-12
这家伙很懒,什么也没写!
\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}

df70800ed806673c6b99375b0b3fcb99.png

test.tex

完美

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览