30 请问如何修改代码来避免下图中的警告?

发布于 2023-03-07 21:44:00

Snipaste_2023-03-07_21-38-32.png

\documentclass{ctexart}
\usepackage{xcolor}
\colorlet{nuanbai}{gray!1}
\usepackage{ninecolors}
\usepackage{tikz}
\usetikzlibrary{calc,shadows}
\usepackage[many]{tcolorbox}
\tcbuselibrary{breakable}
\newcounter{tcbthm}
\def\tcbthmautorefname{\bf 定理}
\newcommand{\Theorem}{定理}
\newtcolorbox{wwtheorem}[3][]{
        arc=3pt,breakable,enhanced,colback=nuanbai,boxrule=0pt,top=8mm,
    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 and label={tcbthm}{#3},
        overlay unbroken = {
      \fill[black!60] ([xshift=1cm,yshift=5pt]frame.north west)-- ([xshift=0.8cm,yshift=0cm]frame.north west)--([xshift=1.2cm,yshift=0cm]frame.north west)--cycle;
            %标题 %更改有效
            \node[rectangle, 
    text=white, drop shadow={opacity=.3, shadow xshift=0.1cm},
    inner sep=1.5mm,fill=purple5,
    anchor=west,rounded corners=3pt,
    font=\normalsize] at ([xshift=0cm,yshift=-3.mm]frame.north west)%
    {\phantom{\rule{1.2em}{0pt}}\bf   \Theorem\ \thetcbthm.~#2};
            \fill[color=purple5,drop shadow={opacity=0.3,shadow xshift=.3pt}] 
            ([xshift=1cm,yshift=5pt]frame.north west) {[rounded corners=3pt]--++(-1cm-5pt,0)}--++(0,-1cm-5pt)--cycle;
      \fill[color=black!60] ([xshift=-5pt,yshift=-1cm]frame.north west)--([xshift=0cm,yshift=-0.8cm]frame.north west)-- ([xshift=0cm,yshift=-1.2cm]frame.north west)--cycle;
            %%============================%% End
            \fill[purple5,drop shadow={opacity=0.3,shadow xshift=-0.008\linewidth,shadow yshift=0.0016\linewidth}] 
            ([xshift=-0.05\linewidth,yshift=-5pt]frame.south east) {[rounded corners=3pt]--++(0.05\linewidth+5pt,0)}--++(0,0.05\linewidth+5pt)--cycle;
            \fill[black!60] ([xshift=-0.05\linewidth,yshift=-5pt]frame.south east) -- ([xshift=-0.04\linewidth,yshift=0pt]frame.south east)-- ([xshift=-0.06\linewidth,yshift=0pt]frame.south east)--cycle;
            \fill[black!60] ([xshift=5pt,yshift=0.05\linewidth]frame.south east)-- ([yshift=0.04\linewidth]frame.south east) -- ([yshift=0.06\linewidth]frame.south east)--cycle;
        },%上面是实际控制代码,下面的代码仅在跨页分割时生效
        overlay first = {%跨页时生效
    \fill[black!60] ([xshift=1cm,yshift=5pt]frame.north west)-- ([xshift=0.8cm,yshift=0cm]frame.north west)--([xshift=1.2cm,yshift=0cm]frame.north west)--cycle;
            %标题 %跨页时生效
            \node[rectangle, 
    text=white, drop shadow={opacity=.3, shadow xshift=0.1cm},
    inner sep=1.5mm,fill=purple5,
    anchor=west,rounded corners=3pt,
    font=\normalsize] at ([xshift=0cm,yshift=-3.mm]frame.north west)%
    {\phantom{\rule{1.2em}{0pt}}\bf  \Theorem\ \thetcbthm.~#2};
            \fill[color=purple5,drop shadow={opacity=0.3,shadow xshift=.3pt}] 
            ([xshift=1cm,yshift=5pt]frame.north west) {[rounded corners=3pt]--++(-1cm-5pt,0)}--++(0,-1cm-5pt)--cycle;
            \fill[color=black!60] ([xshift=-5pt,yshift=-1cm]frame.north west)--([xshift=0cm,yshift=-0.8cm]frame.north west)-- ([xshift=0cm,yshift=-1.2cm]frame.north west)--cycle;
        },%保持边缘的变化
        overlay last = {%跨页时生效
            %%============================%% End
            \fill[purple5,drop shadow={opacity=0.3,shadow xshift=-0.008\linewidth,shadow yshift=0.0016\linewidth}] 
            ([xshift=-0.05\linewidth,yshift=-5pt]frame.south east) {[rounded corners=3pt]--++(0.05\linewidth+5pt,0)}--++(0,0.05\linewidth+5pt)--cycle;
            \fill[black!60] ([xshift=-0.05\linewidth,yshift=-5pt]frame.south east) -- ([xshift=-0.04\linewidth,yshift=0pt]frame.south east)-- ([xshift=-0.06\linewidth,yshift=0pt]frame.south east)--cycle;
            \fill[black!60] ([xshift=5pt,yshift=0.05\linewidth]frame.south east)-- ([yshift=0.04\linewidth]frame.south east) -- ([yshift=0.06\linewidth]frame.south east)--cycle;
        }
        #1
    }
\NewDocumentEnvironment{theorem}{O{} O{} O{}}{\smallskip\begin{wwtheorem}{#1}{#2}#3}{\end{wwtheorem} \smallskip}
\begin{document}
\begin{theorem}
测试1
\end{theorem}

\begin{theorem}
测试2
\end{theorem}
\end{document}

上述代码在使用过程中发现, 一旦出现两个没有设定label的环境时,就会导致出现两个重复定义标签的警告,并且更严重的时,有时候不想设定标签的话,警告就会一个环境一个警告,堆积起来非常恐怖的几百个之多,严重影响了正常的排版作业,所以,请问下这是什么问题导致的?有应该如何修改上述代码以解决此问题?

查看更多

关注者
0
被浏览
994
雾月
雾月 2023-03-08
这家伙很懒,什么也没写!

step and label={tcbthm}{#3} 改成 step={tcbthm}, IfBlankF={#3}{label={#3}}
你这个代码问题太多了,为什么要先定义 wwtheorem,再定义一个 theorem 呢,直接用 \NewTColorBox 就行了,再加上 before pre=\smallskip, after app=\smallskip,或者用环境钩子。
还有,应该这么写 \begin{wwtheorem}[#1]{#2}{#3}
还有 wwtheorem 的定义里,#1 前面没有加上逗号。

MWE:

\documentclass{ctexart}
\usepackage{xcolor}
\colorlet{nuanbai}{gray!1}
\usepackage{ninecolors}
\usepackage{tikz}
\usetikzlibrary{calc,shadows}
\usepackage[many]{tcolorbox}
\tcbuselibrary{breakable,xparse} % 旧版本要 xparse

\newcounter{tcbthm}
\def\tcbthmautorefname{\bf 定理}
\newcommand{\Theorem}{定理}
\NewTColorBox{theorem}{O{} O{} o}
  {arc=3pt,breakable,enhanced,colback=nuanbai,boxrule=0pt,top=8mm,
    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}, IfNoValueF={#3}{label={#3}},
    before pre=\smallskip, after app=\smallskip,
    overlay unbroken = {
      \fill[black!60] ([xshift=1cm,yshift=5pt]frame.north west)-- ([xshift=0.8cm,yshift=0cm]frame.north west)--([xshift=1.2cm,yshift=0cm]frame.north west)--cycle;
            %标题 %更改有效
            \node[rectangle, 
    text=white, drop shadow={opacity=.3, shadow xshift=0.1cm},
    inner sep=1.5mm,fill=purple5,
    anchor=west,rounded corners=3pt,
    font=\normalsize] at ([xshift=0cm,yshift=-3.mm]frame.north west)%
    {\phantom{\rule{1.2em}{0pt}}\bf   \Theorem\ \thetcbthm.~#2};
            \fill[color=purple5,drop shadow={opacity=0.3,shadow xshift=.3pt}] 
            ([xshift=1cm,yshift=5pt]frame.north west) {[rounded corners=3pt]--++(-1cm-5pt,0)}--++(0,-1cm-5pt)--cycle;
      \fill[color=black!60] ([xshift=-5pt,yshift=-1cm]frame.north west)--([xshift=0cm,yshift=-0.8cm]frame.north west)-- ([xshift=0cm,yshift=-1.2cm]frame.north west)--cycle;
            %%============================%% End
            \fill[purple5,drop shadow={opacity=0.3,shadow xshift=-0.008\linewidth,shadow yshift=0.0016\linewidth}] 
            ([xshift=-0.05\linewidth,yshift=-5pt]frame.south east) {[rounded corners=3pt]--++(0.05\linewidth+5pt,0)}--++(0,0.05\linewidth+5pt)--cycle;
            \fill[black!60] ([xshift=-0.05\linewidth,yshift=-5pt]frame.south east) -- ([xshift=-0.04\linewidth,yshift=0pt]frame.south east)-- ([xshift=-0.06\linewidth,yshift=0pt]frame.south east)--cycle;
            \fill[black!60] ([xshift=5pt,yshift=0.05\linewidth]frame.south east)-- ([yshift=0.04\linewidth]frame.south east) -- ([yshift=0.06\linewidth]frame.south east)--cycle;
        },%上面是实际控制代码,下面的代码仅在跨页分割时生效
    overlay first = {%跨页时生效
    \fill[black!60] ([xshift=1cm,yshift=5pt]frame.north west)-- ([xshift=0.8cm,yshift=0cm]frame.north west)--([xshift=1.2cm,yshift=0cm]frame.north west)--cycle;
            %标题 %跨页时生效
    \node[rectangle, 
    text=white, drop shadow={opacity=.3, shadow xshift=0.1cm},
    inner sep=1.5mm,fill=purple5,
    anchor=west,rounded corners=3pt,
    font=\normalsize] at ([xshift=0cm,yshift=-3.mm]frame.north west)%
    {\phantom{\rule{1.2em}{0pt}}\bf  \Theorem\ \thetcbthm.~#2};
    \fill[color=purple5,drop shadow={opacity=0.3,shadow xshift=.3pt}] 
            ([xshift=1cm,yshift=5pt]frame.north west) {[rounded corners=3pt]--++(-1cm-5pt,0)}--++(0,-1cm-5pt)--cycle;
            \fill[color=black!60] ([xshift=-5pt,yshift=-1cm]frame.north west)--([xshift=0cm,yshift=-0.8cm]frame.north west)-- ([xshift=0cm,yshift=-1.2cm]frame.north west)--cycle;
        },%保持边缘的变化
        overlay last = {%跨页时生效
            %%============================%% End
            \fill[purple5,drop shadow={opacity=0.3,shadow xshift=-0.008\linewidth,shadow yshift=0.0016\linewidth}] 
            ([xshift=-0.05\linewidth,yshift=-5pt]frame.south east) {[rounded corners=3pt]--++(0.05\linewidth+5pt,0)}--++(0,0.05\linewidth+5pt)--cycle;
            \fill[black!60] ([xshift=-0.05\linewidth,yshift=-5pt]frame.south east) -- ([xshift=-0.04\linewidth,yshift=0pt]frame.south east)-- ([xshift=-0.06\linewidth,yshift=0pt]frame.south east)--cycle;
            \fill[black!60] ([xshift=5pt,yshift=0.05\linewidth]frame.south east)-- ([yshift=0.04\linewidth]frame.south east) -- ([yshift=0.06\linewidth]frame.south east)--cycle;
        },
     #1}
\begin{document}

\begin{theorem}%[][][],三个可选参数,第一个是键值,第二个是标题,第三个是 label
测试1
\end{theorem}

\begin{theorem}
测试2
\end{theorem}
\end{document}
2 个回答
烟云幻梦
烟云幻梦 2023-03-08
数学系咸鱼一枚!

好的,我马上改,主要是抄的外国人的代码,所以可能问题很多-_-!!

撰写答案

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

发布
问题

分享
好友

手机
浏览

扫码手机浏览