我如何使用 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 }(因為我們仍然需要在右下角切角來製作狗耳朵)。

相關內容