4

I am developing a template and wanted to make a box using the tcolorbox package in a specific way. I would like it so that when the page breaks the box from one page to another, the formatting would look like this: First break box

And on the next page it would look like this: Second break box

Also, when there was no break, that it would look like this: Unbreakable box

So far, my code looks like this:

\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};}}

If anyone knows how to make these very specific small changes I would be very grateful.

2
  • To be clear, set aside the cut upper right corner, the dog ear (that is, the shaded cut corner) should be only 1) at the lower right corner on the upper part of broken boxes and 2) at the upper right corner of the lower part of broken boxes. Is this correct? There should be no dog ears on unbroken boxes? And what about boxes that are broken twice? Mar 3, 2023 at 7:23
  • 1
    For the first question: Yes For the second one: Yes For the last one: For boxes that are broken twice, I need 2 "dog ears", one in the top right and one in the bottom right.
    – Jimeens
    Mar 3, 2023 at 8:05

1 Answer 1

8

I think, what you're after is something like this:

\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}

enter image description here

enter image description here enter image description here

A box that is broken several times would have two dog ears (that is "folded" corners) on the middle part, one in the upper right and one in the lower right corner.


You need several things to set up: First of all, you want every part of the broken box to have the skin enhanced, but by default, they have different skins which also affects rounded borders. Since you define the cut corner on the upper right and lower right corner using rounded corners, we hence need to set skin first = enhanced, skin middle = enhanced, skin last = enhanced.

Then, you add two things using overlays: the actual title next to the boxed title and the dog ears. You hence need to define

  1. overlay unbroken where you only place the title,
  2. overlay first where you place the title and the lower dog ear,
  3. overlay middle where you place the upper and the lower dog ear, and finally
  4. overlay last where you only place the upper dog ear.

You did not show how the lower right corner of an unbroken box should look like, so I assumed that wou want a cut corner there as well. If you don't want a cut corner at the lower right, you can replace the option rounded corners = southeast by extras first and middle = { rounded corners = southeast } (because we still need cut corners at the lower right for the dog ears).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .