如何使用 tcolorbox 进行这些特定修改

如何使用 tcolorbox 进行这些特定修改

我正在开发一个模板,并希望以特定方式使用 tcolorbox 包制作一个框。我希望当页面将框从一页拆分到另一页时,格式将如下所示: 第一个断电箱

下一页看起来会像这样: 第二断路盒

此外,当没有中断时,它看起来会像这样: 牢不可破的盒子

到目前为止,我的代码如下所示:

\definecolor{ChapterBackground}{HTML}{101010}
\definecolor{ChapterForeground}{HTML}{e93820}
\newtcolorbox{solution}[1][]{%
enhanced,
breakable,
boxrule = 0pt,frame hidden,
borderline west = {4pt}{0pt}{ChapterBackground},
colback = CoverForeground!10,
sharp corners,
coltitle = ChapterForeground!85,
rounded corners = southeast,
rounded corners = northeast,
arc is angular,
arc = 3mm,
attach boxed title to top left,
boxed title style = {%
        enhanced,
        colback=ChapterBackground,
        top=0pt,
        bottom=0pt,
        sharp corners,
        rounded corners = northeast,
        arc is angular,
        arc = 2mm,
        colframe = ChapterBackground,
        rightrule = 0pt,
        bottomrule = 0pt,
        toprule = 0pt,
},
title = {\bfseries Solution:},
underlay = {% Leaf fold
    \path[fill = tcbcolback!80!black] ([yshift = 3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2);
    \path[draw = tcbcolframe,
    shorten <=-0.05mm,
    shorten >=-0.05mm, 
    draw opacity=0] ([yshift = 3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2);
},
overlay unbroken and first={%
    \path
    let
    \p1=(title.north east),
    \p2=(frame.north east)
    in
    node[anchor=west,
         color=black!70] 
    at (title.east) {#1};}}

如果有人知道如何进行这些非常具体的小改动,我将不胜感激。

答案1

我认为,你所追求的是这样的:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins, breakable}

\definecolor{ChapterBackground}{HTML}{101010}
\definecolor{ChapterForeground}{HTML}{e93820}
\definecolor{CoverForeground}{HTML}{ee0000}

\newtcolorbox{solution}[1][]{%
    enhanced,
    skin first = enhanced,
    skin middle = enhanced,
    skin last = enhanced,
    breakable,
    boxrule = 0pt,
    frame hidden,
    borderline west = {4pt}{0pt}{ChapterBackground},
    colback = CoverForeground!10,
    coltitle = ChapterForeground!85,
    sharp corners,
    rounded corners = southeast,
    rounded corners = northeast,
    arc is angular,
    arc = 3mm,
    attach boxed title to top left,
    boxed title style = {%
        enhanced,
        colback = ChapterBackground,
        colframe = ChapterBackground,
        top = 0pt,
        bottom = 0pt,
        sharp corners,
        rounded corners = northeast,
        arc is angular,
        arc = 2mm,
        rightrule = 0pt,
        bottomrule = 0pt,
        toprule = 0pt,
    },
    title = {\bfseries Solution:}, 
    overlay unbroken = {%
        \node[anchor=west, color=black!70] at (title.east) {#1};
    },
    overlay first = {%
        \node[anchor=west, color=black!70] at (title.east) {#1};
        \path[fill = tcbcolback!80!black] 
            ([yshift = 3mm]interior.south east) -- ++(-0.4,-0.1) -- ++(0.1,-0.2);
    },
    overlay middle = {%
        \path[fill = tcbcolback!80!black] 
            ([yshift = -3mm]interior.north east) -- ++(-0.4,0.1) -- ++(0.1,0.2);
        \path[fill = tcbcolback!80!black] 
            ([yshift = 3mm]interior.south east) -- ++(-0.4,-0.1) -- ++(0.1,-0.2);
    },
    overlay last = {%
        \path[fill = tcbcolback!80!black] 
            ([yshift = -3mm]interior.north east) -- ++(-0.4,0.1) -- ++(0.1,0.2);
    }
}

\usepackage{lipsum}

\begin{document}

\begin{solution}[This is a box]
\lipsum[1]
\end{solution}

\vspace{5cm}

\begin{solution}[This is a box]
\lipsum[1-2]
\end{solution}

\end{document}

在此处输入图片描述

在此处输入图片描述 在此处输入图片描述

一个破损多次的盒子会在中间部分有两个狗耳(即“折叠”的角),一个在右上角,一个在右下角。


您需要设置几项内容:首先,您希望破损盒子的每个部分都有皮肤enhanced,但默认情况下,它们有不同的皮肤,这也会影响rounded borders。由于您使用定义了右上角和右下角的切角rounded corners,因此我们需要设置skin first = enhanced, skin middle = enhanced, skin last = enhanced

然后,使用叠加层添加两个内容:框状标题旁边的实际标题和狗耳朵。因此,您需要定义

  1. overlay unbroken你只要放标题就可以了,
  2. overlay first放置标题和下方狗耳的位置,
  3. overlay middle把狗的上耳朵和下耳朵放在哪里,最后
  4. overlay last您只需放置狗的上耳朵即可。

您没有展示完整盒子的右下角应该是什么样子,所以我假设您也想在那里切角。如果您不想在右下角切角,您可以将选项替换rounded corners = southeastextras first and middle = { rounded corners = southeast }(因为我们仍然需要在右下角切角以制作狗耳朵)。

相关内容