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

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

这是我上一个问题的后续问题 tcolorbox:可以将可破坏的盒子放在彼此后面(重叠)吗?

我的问题是:如何通过重叠来模拟可破坏盒子内部定义的各种可破坏盒子,使它们看起来像是彼此内部的?定义的盒子例如

\newtcolorbox{}

例如 在此处输入图片描述

答案1

按照提出的想法tcolorbox:可以将可破坏的盒子放在彼此后面(重叠)吗?本规范建议声明三种类型的框:topboxmiddleboxbottombox

topbox必须是所需系列中的第一个,它包含并绘制outer title。在之后,您可以放置​​任意topbox数量的-es,并且该系列以将关闭错误的外部 tcolorbox 的结束。middleboxbottombox

middlebox绘制外线并放大以连接前一个topbox和后一个bottombox。当中间框未断开且放置在页面底部时,它会显示错误的行为。我不知道如何解决它。

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

\newtcolorbox{topbox}[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 first={
        \draw[green!70!black, line width=.5mm, rounded corners]
            ([xshift=-5mm]frame.south west)|-([yshift=1cm]frame.north)-|
            ([xshift=5mm]frame.south east);
        \node[fill=green!70!black, minimum height=5mm, 
            minimum width=\linewidth, anchor=north] at ([yshift=1cm]frame.north) 
            (outertitle) {};
        \node[text=white, anchor=west] at ([xshift=3mm]outertitle.west) {Outer title};
        },
    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}
\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}

在此处输入图片描述

相关内容