如何自定义“可破坏盒子内的可破坏盒子”的标题?

如何自定义“可破坏盒子内的可破坏盒子”的标题?

这个问题是使用重叠的方式将各种定义的可破坏盒子放在可破坏盒子内

我如何才能整合第 162 页的风格手动的易碎盒子套在易碎盒子里? 这更多的是关于位置,代码放在哪里,因为无论我尝试什么,结果都是一样的

答案1

我修改了topboxtcolorbox 以使用三个参数(一个可选参数和两个强制参数),第二个强制参数是外框的标题。这个标题。它不适用于长标题。

\documentclass{article}
\usepackage{varwidth}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{topbox}[3][]{enhanced,
    before skip=2mm,after skip=2mm,
    colback=black!5,colframe=black!50,boxrule=0.2mm,
    attach boxed title to top left={xshift=1cm,yshift*=1mm-\tcboxedtitleheight},
    varwidth boxed title*=-3cm,
    boxed title style={frame code={
            \path[fill=tcbcolback!30!black]
            ([yshift=-1mm,xshift=-1mm]frame.north west)
            arc[start angle=0,end angle=180,radius=1mm]
            ([yshift=-1mm,xshift=1mm]frame.north east)
            arc[start angle=180,end angle=0,radius=1mm];
            \path[left color=tcbcolback!60!black,right color=tcbcolback!60!black,
            middle color=tcbcolback!80!black]
            ([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
            [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
            -- (frame.south east) -- (frame.south west)
            -- ([xshift=-1mm,yshift=-1mm]frame.north west)
            [sharp corners]-- cycle;
        },interior engine=empty,
    },
    fonttitle=\bfseries,
    title={#2},
    enhanced, breakable, 
    enlarge top initially by=1cm,
    %    enlarge bottom finally by=5mm,
    enlarge left by=5mm,
    enlarge right by=5mm,
    width=\linewidth-10mm,
    overlay unbroken and first={
        \draw[green!70!black, line width=.5mm, rounded corners]
        ([xshift=-5mm]frame.south west)|-([yshift=9mm]frame.north)-|
        ([xshift=5mm]frame.south east);
        \coordinate (outernw) at ([shift={(-5mm,1cm)}]frame.north west);
        \node[fill=green!70!black, minimum height=5mm, 
        anchor=north west, text=white, rounded corners] at ([xshift=1cm]outernw) 
        (outertitle) {#3};
        \path[fill=green!30!black]
            ([yshift=-1mm,xshift=-1mm]outertitle.north west)
            arc[start angle=0,end angle=180,radius=1mm]
            ([yshift=-1mm,xshift=1mm]outertitle.north east)
            arc[start angle=180,end angle=0,radius=1mm];
            \path[left color=green!60!black,right color=green!60!black,
            middle color=green!80!black]
            ([xshift=-2mm]outertitle.north west) -- ([xshift=2mm]outertitle.north east)
            [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]outertitle.north east)
            -- (outertitle.south east) -- (outertitle.south west)
            -- ([xshift=-1mm,yshift=-1mm]outertitle.north west)
            [sharp corners]-- cycle;
        \node[text=white] at (outertitle) {#3};

    },
    overlay middle and last={
        \draw[green!70!black, line width=.5mm]
        ([xshift=-5mm]frame.north west)--([xshift=-5mm]frame.south west)
        ([xshift=5mm]frame.north east)--([xshift=5mm]frame.south east);
    },
    #1
}

\newtcolorbox{middlebox}[2][]{
    title=#2,
    enhanced, breakable, 
    %    enlarge top initially by=1cm,
    %    enlarge bottom finally by=5mm,
    enlarge left by=5mm,
    enlarge right by=5mm,
    width=\linewidth-10mm,
    overlay unbroken={
        \draw[green!70!black, line width=.5mm]
        ([shift={(-5mm,5mm)}]frame.north west)--([shift={(-5mm,-5mm)}]frame.south west)
        ([shift={(5mm,5mm)}]frame.north east)--([shift={(5mm,-5mm)}]frame.south east);
    },
    overlay first={
        \draw[green!70!black, line width=.5mm]
        ([shift={(-5mm,5mm)}]frame.north west)--([xshift=-5mm]frame.south west)
        ([shift={(5mm,5mm)}]frame.north east)--([xshift=5mm]frame.south east);
    },
    overlay middle={
        \draw[green!70!black, line width=.5mm]
        ([xshift=-5mm]frame.north west)--([xshift=-5mm]frame.south west)
        ([xshift=5mm]frame.north east)--([xshift=5mm]frame.south east);
    },
    overlay last={
        \draw[green!70!black, line width=.5mm]
        ([xshift=-5mm]frame.north west)--([shift={(-5mm,-5mm)}]frame.south west)
        ([xshift=5mm]frame.north east)--([shift={(5mm,-5mm)}]frame.south east);
    },
    #1
}

\newtcolorbox{bottombox}[2][]{
    title=#2,
    enhanced, breakable, 
    %    enlarge top initially by=1cm,
    enlarge bottom finally by=5mm,
    enlarge left by=5mm,
    enlarge right by=5mm,
    width=\linewidth-10mm,
    overlay unbroken and last={
        \draw[green!70!black, line width=.5mm, rounded corners]
        ([xshift=-5mm]frame.north west)|-([yshift=-5mm]frame.south)
        -|([xshift=5mm]frame.north east);
    },
    overlay first={
        \draw[green!70!black, line width=.5mm]
        ([xshift=-5mm]frame.north west)--([xshift=-5mm]frame.south west)
        ([xshift=5mm]frame.north east)--([xshift=5mm]frame.south east);
    },
    overlay middle={
        \draw[green!70!black, line width=.5mm, rounded corners]
        ([xshift=-5mm]frame.north west)--([xshift=-5mm]frame.south west)
        ([xshift=5mm]frame.north east)--([xshift=5mm]frame.south east);
    },
    #1
}

\begin{document}
    \lipsum[1]
    \begin{topbox}{this is the title}{Outer title}
        \lipsum[1-2]
    \end{topbox}
    \begin{middlebox}[colframe=red, colback=pink!10]{this is the title}
        \lipsum[1-5]
    \end{middlebox}
    \begin{middlebox}[colframe=brown!70!black, colback=brown!10]{this is the title}
        \lipsum[1-2]
    \end{middlebox}
    \begin{bottombox}[colframe=blue, colback=cyan!10]{this is the title}
        \lipsum[1-3]
    \end{bottombox}
    \lipsum[1]
\end{document}

在此处输入图片描述

笔记先前的代码已更新,以兼容 tcolorbox v4.20。如果您使用的是先前版本,请将颜色形式重命名tcbcol...为旧形式 tcbcol@...

相关内容