100 tcolorbox盒子的定制问题

发布于 2026-01-31 14:54:24

这里简单概述下问题:

  1. 我想要根据标题长度切换不同的装饰样式,目前无论长度如何都没法切换成功
  2. 我想要底部装饰采用blur shadow而非drop shadow, 目前会导致标题处的两个装饰丢失不显示,如图image.png
  3. 我想要使得背景的渐变颜色更加柔和,也就是增加middle部分(猜的,但是应该也只能这样了),目前一旦盒子跨页,就会出现背景中间很白,怪怪的,出现了背景颜色断层,目前的背景颜色逻辑貌似是在盒子跨页后,上下部分各画各的,都把top colorbottom color来上一遍,颜色的过度太生硬了且出现了断层,与shade[top/middle/bottom color] 这种比起来还有点差距,希望能有个更好点的方案

下面是MWE:

\documentclass[12pt]{ctexbook}
\usepackage[margin=2cm]{geometry}
\RequirePackage{cncolours,newtx}
\RequirePackage{etoolbox} % 判断函数
\RequirePackage{tikz,calc} %%页面样式设计核心包 %提供\pgfonlayer命令
\usetikzlibrary{cd,calc,shadows,shadows.blur,hobby,intersections, decorations.markings, decorations.pathreplacing,spy,arrows,shapes,fadings,trees,mindmap,patterns,shapes.arrows,shapes.symbols,tikzmark,shapes.geometric,graphs, quotes, angles,decorations.pathmorphing,through,shadings,backgrounds,positioning,fit,arrows.meta,shapes.misc,decorations.shapes}
\pgfdeclarelayer{background} %背景%底层
\pgfdeclarelayer{foreground} %上层
\pgfdeclarelayer{top} %顶部
\pgfdeclarelayer{bottom} %底部
\pgfsetlayers{bottom,background,main,foreground,top}
\RequirePackage[most]{tcolorbox}
\tcbuselibrary{breakable, skins,theorems,minted}

\makeatletter
\tcbset{my@basic@tcbthm/.style={detach title,}}
\newcommand{\@my@newtcbtheorem@n}[1]{\ERROR}
\newcommand{\@my@newtcbtheorem@nn}[2]{%
   \@ifundefined{#1}{\@my@newtcbtheorem{#1}{#2}}{\@my@renewtcbtheorem{#1}{#2}}}
\newcommand{\@my@newtcbtheorem}[2]{%
   \edef\my@curr@thmenvname{#1}% 它保存当前定理环境的名称
   \mytcbtheoremset{#2}%
   \NewTColorBox{#1}{ O{} O{} o }
   {my@basic@tcbthm, my@#1@tcbthmstyle, title={##2}, IfNoValueF={##3}{label={##3}}, ##1}}
\newcommand{\@my@renewtcbtheorem}[2]{\edef\my@curr@thmenvname{#1}\mytcbtheoremset{#2}}

% 键值设置
\pgfkeys{/mytcbtheorem/.is family}
\newcommand{\mytcbtheoremset}{\pgfqkeys{/mytcbtheorem}}
\mytcbtheoremset{
name/.code=\@namedef{\my@curr@thmenvname @name}{#1}, %无效
counter/.code=\@namedef{my@\my@curr@thmenvname @counter}{#1}\newcounter{#1}[chapter], % 计数器遇到subsection就会自动归零 % https://zhuanlan.zhihu.com/p/57454848#circle=on
the counter/.code=\@namedef{the\@nameuse{my@\my@curr@thmenvname @counter}}{#1},
autoref name/.code=\@namedef{\@nameuse{my@\my@curr@thmenvname @counter}autorefname}{#1},
style/.code=\tcbset{my@\my@curr@thmenvname @tcbthmstyle/.style={#1}},
thmcolor/.code=\@namedef{\my@curr@thmenvname @thmcolor}{#1}, %无效
lemcolor/.code=\@namedef{\my@curr@thmenvname @lemcolor}{#1}, %无效
}
% 存储键值 (LaTeX3)
\ExplSyntaxOn
\cs_new_protected:Npn \mynewtheorem
{ \keyval_parse:NNn \@my@newtheorem@n \@my@newtheorem@nn }
\cs_new_protected:Npn \mynewtcbtheorem
{ \keyval_parse:NNn \@my@newtcbtheorem@n \@my@newtcbtheorem@nn }
\ExplSyntaxOff

% /* ------------------ Second theorem style overlay settings ----------------- */
%%定义标题文字长度%%
\newlength{\thmtcbtextlen}
%%设置临界长度%%
\newlength{\thmcriticstarlen}
\setlength{\thmcriticstarlen}{.6\linewidth}
%
\newcommand{\my@lemma@overlay@unbroken}[2]{
   %%============== First ==============%%
   \def\rad{7pt}%
   \settowidth{\thmtcbtextlen}{\hspace*{10pt}#1.\ \ifdefvoid{\tcbtitletext}{}{(\itshape\tcbtitletext)}}
   \begin{scope}
      \path[fill=#2, blur shadow={shadow blur steps=10,shadow xshift=-1pt, shadow yshift=-1pt,shadow blur radius=1.5pt,shadow opacity=35}
      ]node[append after command={
               ([xshift=-1.5*\rad]thmname.north west) to[out=0,in=180,looseness=1] ([xshift=2.5*\rad]thmname.south west) --([xshift=-\rad]thmname.south east) to[out=0,in=180,looseness=1] ([xshift=3*\rad]thmname.north east) --cycle},
         text=white,font=\bfseries,align=center,inner ysep=1.5mm,minimum height=0.6cm,right] (thmname) at ([xshift=\rad,yshift=-.7*\rad]frame.north west) {\hspace*{10pt}#1.\ \ifdefvoid{\tcbtitletext}{}{(\itshape\tcbtitletext)}};

      %%============== 两边的阴影/折叠部分 ==============%%
      \begin{pgfonlayer}{bottom}
         % 左侧翅膀样式一
         % \shade[left color=#2!20, right color=#2!80!black]
         % ([xshift=-1.5*\rad]thmname.north west)
         % to[out=180, in=0] ++(-2*\rad, -\rad)
         % -| +(5*\rad,\rad)
         % -- cycle;
         % /* -------------------------------------------------------------------------- */
         % 左侧翅膀样式二:镜像翻转为向上折叠效果
         \shade[left color=#2!20, right color=#2!80!black]
         ([shift={(-.5*\rad,-\rad)}]thmname.north west)
         to[out=180, in=0] ++(-2*\rad, \rad) % 将 -\rad 改为 \rad,使其向上延伸
         -| +(5*\rad, -\rad)                 % 将 \rad 改为 -\rad,使其向下回到主体水平线
         -- cycle;
         % 右侧翅膀:完全镜像处理
         % \shade[right color=#2!20, left color=#2!80!black]
         % ([xshift=3*\rad]thmname.north east) % 注意这里起点需对应你核心代码中的 3*\rad
         % to[out=0, in=180] ++(2*\rad, -\rad) % 镜像:out 180->0, in 0->180, x -2->2
         % -| +(-5*\rad,\rad)                % 镜像:x 5->-5
         % -- cycle;
         % ===== 右翅膀按条件切换 =====
         %判断标题文字长度与临界长度的关系
         \ifdim\thmtcbtextlen>\thmcriticstarlen
            %-------- 右侧小翅膀:上下翻转版本 --------
            \shade[right color=#2!20, left color=#2!80!black]
               ([xshift=2*\rad,yshift=-1*\rad]thmname.north east)
               to[out=0, in=180] ++(2*\rad, \rad)
               -| +(-5*\rad,-\rad)
               -- cycle;
         \else
            % -------- 右侧小翅膀:原版本 --------
            \shade[right color=#2!20, left color=#2!80!black]
               ([xshift=3*\rad]thmname.north east)
               to[out=0, in=180] ++(2*\rad, -\rad)
               -| +(-5*\rad,\rad)
               -- cycle;
         \fi
      \end{pgfonlayer}
   \end{scope}
   %
   %%============== End ==============%%
   \def\tlen{1.5cm}
   \def\Rad{3.5pt}
   \def\theight{0.5cm}
   \begin{scope} % <--- 添加 scope 隔离环境
      \path[fill=#2,
      drop shadow={opacity=0.3,shadow xshift=.3pt}
    %   blur shadow={shadow blur steps=10,shadow xshift=-1pt, shadow yshift=-1pt,shadow blur radius=1.5pt,shadow opacity=35} %一旦改成这个就会报错
      ]
      ([xshift=-2*\rad,yshift=-5pt]frame.south east) coordinate (SE)  to[out=0,in=180] +(4*\rad,5pt+\theight) --([shift={(-\tlen+4*\rad,5pt+\theight)}]SE) to[out=180,in=0] +(-4*\rad,-5pt-\theight) --cycle;
      \begin{pgfonlayer}{bottom}
         % 左侧翅膀:镜像翻转为向上折叠效果
         \shade[left color=#2!20, right color=#2!80!black]
         ([shift={(-1.35*\tlen+\Rad,-5pt)}]frame.south east)
         to[out=180, in=0] ++(-2*\rad, \rad) % 将 -\rad 改为 \rad,使其向上延伸
         -| +(5*\rad, -\rad)                 % 将 \rad 改为 -\rad,使其向下回到主体水平线
         -- cycle;
      \end{pgfonlayer}
   \end{scope}
}

\mynewtcbtheorem{
theorem={
      counter=tcbthm,
      the counter=\thesection.\arabic{tcbthm},
      autoref name=\bfseries Theorem,
      style={
          arc=0mm,breakable,enhanced,
                   % 针对跨页片段的特殊处理
         extras first={
               bottom=3mm, % 第一段的底部不需要留白
            },
         extras middle={
               top=3mm,    % 中间段的顶部不需要留白
               bottom=0mm, % 中间段的底部不需要留白
            },
         extras last={
               top=0mm,    % 最后一段的顶部不需要留白
            },
         % 建议同时加入以下设置以确保彻底消除干扰
         pad at break=2mm,
         bottomsep at break=0mm,
         topsep at break=2mm,
          interior style={top color=黛绿!9 ,middle color=黛绿!6, bottom color=黛绿!3},arc=3pt,boxrule=0pt,top=6mm,bottom=5mm,
          fuzzy shadow={-0.6mm}{0.6mm}{0mm}{0.3mm}{white!50!gray},% 上
          fuzzy shadow={0.6mm}{-0.6mm}{0mm}{0.3mm}{fill=white!40!gray},%下
          opacityframe=0, opacityback=0.98,
          fontupper=\itshape,step={tcbthm},
          before pre=\smallskip, after app=\smallskip,
          overlay unbroken=\my@lemma@overlay@unbroken{Theorem\ \thetcbthm}{黛绿},
          overlay first=\my@lemma@overlay@first{Theorem\ \thetcbthm}{黛绿},
          overlay last=\my@lemma@overlay@last{黛绿},
        }
    },
}
\makeatother
\begin{document}
\chapter{Test}
\begin{theorem}[][Semidefinite vanishing theorem for vector bundle of rank $k$ (General Case)][thm:Semidefinite vanishing theorem for vector bundle of rank $k$ (General Case)]
   Let $M$ be a compact complex manifold, and assume that there exists a hermitian metric on $E$, whose curvature tensor $\Theta$ satisfies the following condition at each point of $M$.
        
   For any $\zeta\in C^r-0$, the quadratic form in $\eta,\Theta(\zeta,\eta)$, has at least $n-k_1$ positive eigenvalues and at least $k_2$ negative eigenvalues. Then 
    \[H^q(M,\Omega(S^\mu E\otimes D))=0\]
    for any $q\not\in (k_1,\ldots,k_2)$ if $\mu\geq 0$.
\end{theorem}
\end{document}

查看更多

关注者
1
被浏览
162
3 个回答
Sagittarius Rover
这家伙很懒,什么也没写!

问题要一个一个问,同时尽可能详细描述。 且同时问多个问题会令人难以回答,也会导致问题严重缺少针对性。试想有人需要查询类似问题,看到这个页面十分难以知道解决问题的核心点在哪里,会大大削弱本提问站的意义。

从你上述的描述中:

我想要根据标题长度切换不同的装饰样式,目前无论长度如何都没法切换成功?

不能期望别人很快读完这100多行之后准确get到什么是「目前无论长度如何都没法切换成功」。请详细说明你是具体是用哪些代码,具体是如何切换的,又是如何体现的「不成功」。

我想要底部装饰采用blur shadow而非drop shadow, 目前报错

如果遇到报错,请贴出命令行的报错信息。我将你的代码中的:

drop shadow={opacity=0.3,shadow xshift=.3pt}

替换为你注释掉的

blur shadow={shadow blur steps=10,shadow xshift=-1pt, shadow yshift=-1pt,shadow blur radius=1.5pt,shadow opacity=35} %一旦改成这个就会报错

tcolorbox-v6.9.0下并没有报错。

我想要使得背景的渐变颜色更加柔和,也就是增加middle部分(猜的,但是应该也只能这样了),目前一旦盒子跨页,就会出现背景中间很白,怪怪的,出现了背景颜色断层,目前的背景颜色逻辑貌似是在盒子跨页后,上下部分各画各的,都把top colorbottom color来上一遍,颜色的过度太生硬了且出现了断层,与shade[top/middle/bottom color] 这种比起来还有点差距,希望能有个更好点的方案

问题描述中出现了"跨页",以及大量对颜色形态的描述。但你提供的代码中盒子并未跨页,也缺少图示说明背景颜色如何令人不满意。没有人有魔法水晶球知道你想表达什么。请用提供图片和能直接体现这个需求的例子,另开问题询问为佳。

Sagittarius Rover
这家伙很懒,什么也没写!

问题0:

直接编译你的代码会得到一长串的警告:

Missing character: There is no T ("54) in font nullfont!
Missing character: There is no h ("68) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no o ("6F) in font nullfont!
Missing character: There is no r ("72) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no m ("6D) in font nullfont!
Missing character: There is no 1 ("31) in font nullfont!
Missing character: There is no . ("2E) in font nullfont!
Missing character: There is no 0 ("30) in font nullfont!
Missing character: There is no . ("2E) in font nullfont!
Missing character: There is no 1 ("31) in font nullfont!
Missing character: There is no . ("2E) in font nullfont!
Missing character: There is no ( ("28) in font nullfont!
Missing character: There is no S ("53) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no m ("6D) in font nullfont!
Missing character: There is no i ("69) in font nullfont!
Missing character: There is no d ("64) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no f ("66) in font nullfont!
Missing character: There is no i ("69) in font nullfont!
Missing character: There is no n ("6E) in font nullfont!
Missing character: There is no i ("69) in font nullfont!
Missing character: There is no t ("74) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no v ("76) in font nullfont!
Missing character: There is no a ("61) in font nullfont!
Missing character: There is no n ("6E) in font nullfont!
Missing character: There is no i ("69) in font nullfont!
Missing character: There is no s ("73) in font nullfont!
Missing character: There is no h ("68) in font nullfont!
Missing character: There is no i ("69) in font nullfont!
Missing character: There is no n ("6E) in font nullfont!
Missing character: There is no g ("67) in font nullfont!
Missing character: There is no t ("74) in font nullfont!
Missing character: There is no h ("68) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no o ("6F) in font nullfont!
Missing character: There is no r ("72) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no m ("6D) in font nullfont!
Missing character: There is no f ("66) in font nullfont!
Missing character: There is no o ("6F) in font nullfont!
Missing character: There is no r ("72) in font nullfont!
Missing character: There is no v ("76) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no c ("63) in font nullfont!
Missing character: There is no t ("74) in font nullfont!
Missing character: There is no o ("6F) in font nullfont!
Missing character: There is no r ("72) in font nullfont!
Missing character: There is no b ("62) in font nullfont!
Missing character: There is no u ("75) in font nullfont!
Missing character: There is no n ("6E) in font nullfont!
Missing character: There is no d ("64) in font nullfont!
Missing character: There is no l ("6C) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no o ("6F) in font nullfont!
Missing character: There is no f ("66) in font nullfont!
Missing character: There is no r ("72) in font nullfont!
Missing character: There is no a ("61) in font nullfont!
Missing character: There is no n ("6E) in font nullfont!
Missing character: There is no k ("6B) in font nullfont!
Missing character: There is no ( ("28) in font nullfont!
Missing character: There is no G ("47) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no n ("6E) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no r ("72) in font nullfont!
Missing character: There is no a ("61) in font nullfont!
Missing character: There is no l ("6C) in font nullfont!
Missing character: There is no C ("43) in font nullfont!
Missing character: There is no a ("61) in font nullfont!
Missing character: There is no s ("73) in font nullfont!
Missing character: There is no e ("65) in font nullfont!
Missing character: There is no ) ("29) in font nullfont!
Missing character: There is no ) ("29) in font nullfont!

这不是可忽视的警告!

出现问题的语句是要传给overlay unbroken中的\settowidth

\newcommand{\my@lemma@overlay@unbroken}[2]{
   %%============== First ==============%%
   \def\rad{7pt}%
   \settowidth{\thmtcbtextlen}{\hspace*{10pt}#1.\ \ifdefvoid{\tcbtitletext}{}{(\itshape\tcbtitletext)}} %<-

这个问题的一个等价的MWE如下:

\documentclass{article}
\usepackage[most]{tcolorbox}
\newlength{\mylength}
\newcommand\mycmd[1]{%
    \settowidth{\mylength}{abcdefg}
    \node at (frame.south west) {\the\mylength};
    \draw[ultra thick,magenta] 
        (frame.north west) 
        -- 
        ([xshift=\mylength]frame.north west)
        node[right,font=\ttfamily] {#1:\the\mylength}
    ;
}
\begin{document}
\begin{tcolorbox}[
        title=A Simple Box,enhanced,
        overlay={\mycmd{A Simple Box}}
    ]
    This is a simple tcolorbox.
\end{tcolorbox}

\newlength{\anotherlength}
\settowidth{\anotherlength}{abcdefg}
\texttt{\the\anotherlength}

\end{document}

这个MWE编译会得到如下警告:

Missing character: There is no a in font nullfont!
Missing character: There is no b in font nullfont!
Missing character: There is no c in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no f in font nullfont!
Missing character: There is no g in font nullfont!

且对宽度的测量是不准确的。

image.png


该问题又可以进一步简化为「在tikz环境内不能直接使用\settowidth」:

\documentclass[tikz,border=5pt]{standalone}
\newlength{\mylength}
\begin{document}
\begin{tikzpicture}
    \settowidth{\mylength}{abcde}
    % \settowidth{\mylength}{\pgfinterruptpicture abcde\endpgfinterruptpicture}
    \draw (0,0) -- (\mylength,0) node[above right] {\the\mylength};
\end{tikzpicture}

\end{document}

会出现警告:

Missing character: There is no a in font nullfont!
Missing character: There is no b in font nullfont!
Missing character: There is no c in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no e in font nullfont!

image.png

解决方法和解释在这里

不知道是不是:

我想要根据标题长度切换不同的装饰样式,目前无论长度如何都没法切换成功

的一个体现。

雾月
雾月 19小时前
这家伙很懒,什么也没写!
  1. 计算宽度要用 interrupt 环境,直接在绘图环境里是不行的。
  2. blur shadow 里创建了新的绘图环境,盲猜是因为这个把原本的 bottom 图层清空了,解决办法同 1,把标题样式放到单独的绘图环境,先让它画完这部分,就不会被后面影响了。
  3. 分别在 extra unbroken/first/middle/last 里使用 /tcb/interior code 重写 interior,让 first 末尾的颜色等于 middle 开始的颜色,依此类推,但 middle 部分最好不使用渐变,因为 tcb 好像没有直接判断是否是 unbroken 还是 first-middle-last 还是 first-last,需要 hack。

我实现了 1,2。对于 3,middle 不使用渐变的情况下应该不难。

\documentclass[12pt]{ctexbook}
\usepackage{lipsum}
\usepackage[margin=2cm]{geometry}
\RequirePackage{cncolours,newtx}
\RequirePackage{etoolbox} % 判断函数
\RequirePackage{tikz,calc} %%页面样式设计核心包 %提供\pgfonlayer命令
\usetikzlibrary{cd,calc,shadows,shadows.blur,hobby,intersections, decorations.markings, decorations.pathreplacing,spy,arrows,shapes,fadings,trees,mindmap,patterns,shapes.arrows,shapes.symbols,tikzmark,shapes.geometric,graphs, quotes, angles,decorations.pathmorphing,through,shadings,backgrounds,positioning,fit,arrows.meta,shapes.misc,decorations.shapes}
\pgfdeclarelayer{background} %背景%底层
\pgfdeclarelayer{foreground} %上层
\pgfdeclarelayer{top} %顶部
\pgfdeclarelayer{bottom} %底部
\pgfsetlayers{bottom,background,main,foreground,top}
\RequirePackage[most]{tcolorbox}
\tcbuselibrary{breakable, skins,theorems,minted}

\makeatletter
\tcbset{my@basic@tcbthm/.style={detach title,}}
\newcommand{\@my@newtcbtheorem@n}[1]{\ERROR}
\newcommand{\@my@newtcbtheorem@nn}[2]{%
  \@ifundefined{#1}{\@my@newtcbtheorem{#1}{#2}}{\@my@renewtcbtheorem{#1}{#2}}}
\newcommand{\@my@newtcbtheorem}[2]{%
  \edef\my@curr@thmenvname{#1}% 它保存当前定理环境的名称
  \mytcbtheoremset{#2}%
  \NewTColorBox{#1}{ O{} O{} o }
  {my@basic@tcbthm, my@#1@tcbthmstyle, title={##2}, IfNoValueF={##3}{label={##3}}, ##1}}
\newcommand{\@my@renewtcbtheorem}[2]{\edef\my@curr@thmenvname{#1}\mytcbtheoremset{#2}}

% 键值设置
\pgfkeys{/mytcbtheorem/.is family}
\newcommand{\mytcbtheoremset}{\pgfqkeys{/mytcbtheorem}}
\mytcbtheoremset{
  name/.code=\@namedef{\my@curr@thmenvname @name}{#1}, %无效
  counter/.code=\@namedef{my@\my@curr@thmenvname @counter}{#1}\newcounter{#1}[chapter],
  % 计数器遇到subsection就会自动归零 % https://zhuanlan.zhihu.com/p/57454848#circle=on
  the counter/.code=\@namedef{the\@nameuse{my@\my@curr@thmenvname @counter}}{#1},
  autoref name/.code=\@namedef{\@nameuse{my@\my@curr@thmenvname @counter}autorefname}{#1},
  style/.code=\tcbset{my@\my@curr@thmenvname @tcbthmstyle/.style={#1}},
  thmcolor/.code=\@namedef{\my@curr@thmenvname @thmcolor}{#1}, %无效
  lemcolor/.code=\@namedef{\my@curr@thmenvname @lemcolor}{#1}, %无效
}
% 存储键值 (LaTeX3)
\ExplSyntaxOn
\cs_new_protected:Npn \mynewtheorem
   { \keyval_parse:NNn \@my@newtheorem@n \@my@newtheorem@nn }
\cs_new_protected:Npn \mynewtcbtheorem
{ \keyval_parse:NNn \@my@newtcbtheorem@n \@my@newtcbtheorem@nn }
\ExplSyntaxOff

% /* ------------------ Second theorem style overlay settings ----------------- */
%%定义标题文字长度%%
\newlength{\thmtcbtextlen}
%%设置临界长度%%
\newlength{\thmcriticstarlen}
\setlength{\thmcriticstarlen}{.6\linewidth}
%
\def\my@thm@a#1#2{%
  \begin{scope}
    \path[
      fill=#2,
      drop shadow={shadow blur steps=10,shadow xshift=-1pt, shadow yshift=-1pt,shadow blur radius=1.5pt,shadow opacity=35}
    ]
    node
    [
      append after command={
        ([xshift=-1.5*\rad]thmname.north west) to[out=0,in=180,looseness=1] ([xshift=2.5*\rad]thmname.south west) --([xshift=-\rad]thmname.south east) to[out=0,in=180,looseness=1] ([xshift=3*\rad]thmname.north east) --cycle},
      text=white,font=\bfseries,align=center,inner ysep=1.5mm,minimum height=0.6cm,right
    ]
    (thmname) at
    ([xshift=\rad,yshift=-.7*\rad]frame.north west)
    {\hspace*{10pt}#1.\ \ifdefvoid{\tcbtitletext}{}{(\itshape\tcbtitletext)}};

    %%============== 两边的阴影/折叠部分 ==============%%
    \my@thm@a@layer{#1}{#2}
  \end{scope}%
}
\def\my@thm@a@layer#1#2{%
  \begin{pgfonlayer}{bottom}
      % 左侧翅膀样式一
      % \shade[left color=#2!20, right color=#2!80!black]
      % ([xshift=-1.5*\rad]thmname.north west)
      % to[out=180, in=0] ++(-2*\rad, -\rad)
      % -| +(5*\rad,\rad)
      % -- cycle;
      % /* -------------------------------------------------------------------------- */
      % 左侧翅膀样式二:镜像翻转为向上折叠效果
      \shade[left color=#2!20, right color=#2!80!black]
      ([shift={(-.5*\rad,-\rad)}]thmname.north west)
      to[out=180, in=0] ++(-2*\rad, \rad) % 将 -\rad 改为 \rad,使其向上延伸
      -| +(5*\rad, -\rad)                 % 将 \rad 改为 -\rad,使其向下回到主体水平线
      -- cycle;
      % 右侧翅膀:完全镜像处理
      % \shade[right color=#2!20, left color=#2!80!black]
      % ([xshift=3*\rad]thmname.north east) % 注意这里起点需对应你核心代码中的 3*\rad
      % to[out=0, in=180] ++(2*\rad, -\rad) % 镜像:out 180->0, in 0->180, x -2->2
      % -| +(-5*\rad,\rad)                % 镜像:x 5->-5
      % -- cycle;
      % ===== 右翅膀按条件切换 =====
      %判断标题文字长度与临界长度的关系
      \ifdim\thmtcbtextlen>\thmcriticstarlen
        %-------- 右侧小翅膀:上下翻转版本 --------
        \shade[right color=#2!20, left color=#2!80!black]
            ([xshift=2*\rad,yshift=-1*\rad]thmname.north east)
            to[out=0, in=180] ++(2*\rad, \rad)
            -| +(-5*\rad,-\rad)
            -- cycle;
      \else
        % -------- 右侧小翅膀:原版本 --------
        \shade[right color=#2!20, left color=#2!80!black]
            ([xshift=3*\rad]thmname.north east)
            to[out=0, in=180] ++(2*\rad, -\rad)
            -| +(-5*\rad,\rad)
            -- cycle;
      \fi
  \end{pgfonlayer}
}
\def\my@thm@b#1#2{%
  \begin{scope} % <--- 添加 scope 隔离环境
    \path[fill=#2,
    % drop shadow={opacity=0.3,shadow xshift=.3pt}
    blur shadow={shadow blur steps=10,shadow xshift=-1pt, shadow yshift=-1pt,shadow blur radius=1.5pt,shadow opacity=35}
    ]
    ([xshift=-2*\rad,yshift=-5pt]frame.south east) coordinate (SE)  to[out=0,in=180] +(4*\rad,5pt+\theight) --([shift={(-\tlen+4*\rad,5pt+\theight)}]SE) to[out=180,in=0] +(-4*\rad,-5pt-\theight) --cycle;
    \begin{pgfonlayer}{bottom}
        % 左侧翅膀:镜像翻转为向上折叠效果
        \shade[left color=#2!20, right color=#2!80!black]
        ([shift={(-1.35*\tlen+\Rad,-5pt)}]frame.south east)
        to[out=180, in=0] ++(-2*\rad, \rad) % 将 -\rad 改为 \rad,使其向上延伸
        -| +(5*\rad, -\rad)                 % 将 \rad 改为 -\rad,使其向下回到主体水平线
        -- cycle;
    \end{pgfonlayer}
  \end{scope}%
}
\newcommand{\my@lemma@overlay@unbroken}[2]{
   %%============== First ==============%%
  \def\rad{7pt}%
  %%% 注意这里!
  \begin{pgfinterruptpicture}
    \settowidth{\thmtcbtextlen}{\hspace*{10pt}#1.\ \ifdefvoid{\tcbtitletext}{}{(\itshape\tcbtitletext)}}
    % \global\thmtcbtextlen\thmtcbtextlen % \my@thm@a放到interrupt环境外面就需要global
    \begin{tikzpicture}
      % 这里可能需要调整细节!
      \path[use as bounding box]([xshift=\rad]frame.north west) rectangle (frame.south east);
      \my@thm@a{#1}{#2}%
    \end{tikzpicture}
  \end{pgfinterruptpicture}
  % \my@thm@a{#1}{#2}% 把它放到单独的tikz环境里,如上
   %
   %%============== End ==============%%
   \def\tlen{1.5cm}
   \def\Rad{3.5pt}
   \def\theight{0.5cm}
  \my@thm@b{#1}{#2}
}

%% first 和 last 没在 MWE 里!
\newcommand\my@lemma@overlay@first[2]{
  \def\rad{7pt}%
  \begin{pgfinterruptpicture}
    \settowidth{\thmtcbtextlen}{\hspace*{10pt}#1.\ \ifdefvoid{\tcbtitletext}{}{(\itshape\tcbtitletext)}}
    % \global\thmtcbtextlen\thmtcbtextlen % \my@thm@a放到interrupt环境外面就需要global
    \begin{tikzpicture}
      \path[use as bounding box]([xshift=\rad]frame.north west) rectangle (frame.south east);
      \my@thm@a{#1}{#2}%
    \end{tikzpicture}
  \end{pgfinterruptpicture}
}
\newcommand\my@lemma@overlay@last[1]{
  \def\rad{7pt}%
  \def\tlen{1.5cm}
  \def\Rad{3.5pt}
  \def\theight{0.5cm}
  \my@thm@b{}{#1}
}

\mynewtcbtheorem{
  theorem={
    counter=tcbthm,
    the counter=\thesection.\arabic{tcbthm},
    autoref name=\bfseries Theorem,
    style={
      arc=0mm,breakable,enhanced,
                % 针对跨页片段的特殊处理
      extras first={
            bottom=3mm, % 第一段的底部不需要留白
        },
      extras middle={
            top=3mm,    % 中间段的顶部不需要留白
            bottom=0mm, % 中间段的底部不需要留白
        },
      extras last={
            top=0mm,    % 最后一段的顶部不需要留白
        },
      % 建议同时加入以下设置以确保彻底消除干扰
      pad at break=2mm,
      bottomsep at break=0mm,
      topsep at break=2mm,
      interior style={top color=黛绿!9 ,middle color=黛绿!6, bottom color=黛绿!3},arc=3pt,boxrule=0pt,top=6mm,bottom=5mm,
      fuzzy shadow={-0.6mm}{0.6mm}{0mm}{0.3mm}{white!50!gray},% 上
      fuzzy shadow={0.6mm}{-0.6mm}{0mm}{0.3mm}{fill=white!40!gray},%下
      opacityframe=0, opacityback=0.98,
      fontupper=\itshape,step={tcbthm},
      before pre=\smallskip, after app=\smallskip,
      overlay unbroken=\my@lemma@overlay@unbroken{Theorem\ \thetcbthm}{黛绿},
      overlay first=\my@lemma@overlay@first{Theorem\ \thetcbthm}{黛绿},
      overlay last=\my@lemma@overlay@last{黛绿},
    }
  },
}
\makeatother
\begin{document}
\chapter{Test}
\begin{theorem}[][Semidefinite vanishing theorem for vector bundle of rank $k$ (General Case)][thm:Semidefinite vanishing theorem for vector bundle of rank $k$ (General Case)]
   Let $M$ be a compact complex manifold, and assume that there exists a hermitian metric on $E$, whose curvature tensor $\Theta$ satisfies the following condition at each point of $M$.
        
   For any $\zeta\in C^r-0$, the quadratic form in $\eta,\Theta(\zeta,\eta)$, has at least $n-k_1$ positive eigenvalues and at least $k_2$ negative eigenvalues. Then 
    \[H^q(M,\Omega(S^\mu E\otimes D))=0\]
    for any $q\not\in (k_1,\ldots,k_2)$ if $\mu\geq 0$.
\end{theorem}

\begin{theorem}[][lorem lipsum]
  \lipsum[1-10]
\end{theorem}
\end{document}

撰写答案

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

发布
问题

分享
好友

手机
浏览

扫码手机浏览