3

I would like to define a breakable tcolorbox whose interior contains no color or other drawing code, so displays whatever color is behind it. tcolorbox with the skins library has the options interior empty and interior hidden which control the drawing of the interior, though I struggling to understand the interaction between these keys and the corresponding frame empty and frame hidden. I would expect the former keys to print the frame surrounding the box's contents with nothing done to the interior, but instead the box is printed with a dark gray background.

From this answer, I see that we can get around this by setting both frame empty and interior empty then drawing the frame with borderline. This works for unbroken boxes, but if a box is broken then it seems the frame empty and interior empty keys are ignored and the tcolorbox defaults go into effect.

\documentclass{article}

\usepackage[skins,breakable]{tcolorbox} \usepackage{kantlipsum}

\pagecolor{yellow!10}

\tcbset{enhanced}

\begin{document}

\begin{tcolorbox}[ interior empty ] This is a \textbf{tcolorbox}. \end{tcolorbox}

\begin{tcolorbox}[ interior empty, frame empty % don't want hidden frame ] This is a \textbf{tcolorbox}. \end{tcolorbox}

\begin{tcolorbox}[ interior hidden ] This is a \textbf{tcolorbox}. \end{tcolorbox}

\begin{tcolorbox}[ interior hidden, frame hidden, % don't want hidden frame ] This is a \textbf{tcolorbox}. \end{tcolorbox}

\begin{tcolorbox}[ frame empty, interior empty, borderline={1pt}{0pt}{}, ] This is a \textbf{tcolorbox}. \end{tcolorbox}

\begin{tcolorbox}[ breakable, frame empty, interior empty, borderline={1pt}{0pt}{}, ] This is a \textbf{tcolorbox}. \kant[1-3] \end{tcolorbox} \end{document}

tcbox

I'm probably misunderstanding what is really meant by "frame" and "interior", but is there a way to make a breakable tcolorbox with an empty interior?

Edit

As samcarter_is_at_topanswers.xyz points out in the comments, the "frame" is a filled rectangle behind the box, not a line drawn around it. This explains the output with interior empty and interior hidden.

I've also discovered that breakable does not interact nicely with frame empty and interior empty in general:

\begin{tcolorbox}[
  breakable,
  interior empty,
  frame empty
  ]
This is a \textbf{tcolorbox}.
\kant[1-5]
\end{tcolorbox}

This resets the frame and interior defaults when broken.

For context, I'm trying to adapt this answer for emulating thmbox with tcolorbox to use the page background color, not the preset background color white, since this is the behavior of thmbox.

mbert
  • 4,171

4 Answers4

3

Instead of actually making the tcolorbox transparent, you could make it look transparent by colouring it in the same colour as the page:

\documentclass{article}
\usepackage{xcolor}
\usepackage[skins,breakable]{tcolorbox}
\usepackage{kantlipsum}
\usepackage{pagecolor}

\pagecolor{yellow}

\tcbset{enhanced}

\begin{document}

\begin{tcolorbox}[ breakable, colback=\thepagecolor ] This is a \textbf{tcolorbox}. \kant[1-5] \end{tcolorbox}

\end{document}

enter image description here

  • +1 Thanks, this is a good workaround. I was hoping for a "nicer" way that really makes the interior drawing code empty (then I could draw the frame code manually), but I don't think that's possible with breakable – mbert Jan 02 '24 at 17:47
3

While frame empty and interior empty do not work as expected when given with breakable, they do work if given to the extras key. This way we can fake the frame with borderline.

\documentclass{article}

\usepackage[skins,breakable]{tcolorbox} \usepackage{kantlipsum}

\pagecolor{yellow!10}

\begin{document}

\begin{tcolorbox}[ breakable, extras={frame empty,interior empty}, borderline={1pt}{0pt}{} ] This is a \textbf{tcolorbox}. \kant[1-5] \end{tcolorbox}

\end{document}

breakable box

mbert
  • 4,171
3

For context, I'm trying to adapt this answer for emulating thmbox with tcolorbox to use the page background color, not the preset background color white, since this is the behavior of thmbox.

It seems you need

\tcbset{
    thmbox/.style={
        % ...
        % colback=white,
        % colframe=white,
        % colbacktitle=white,
        %% in order to imitate effect of "enhanced jigsaw, boxrule=0pt"
        frame engine=empty,
        interior titled engine=empty,
        interior engine=empty,
        extras broken={
          frame engine=empty,
          interior titled engine=empty,
          interior engine=empty
        },
        % ...
    }
}

enter image description here

Full example, based on the linked @Ignasi's answer:

\documentclass{article}
\usepackage{amssymb}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{breakable, skins, theorems}

\pagecolor{yellow!10}

\tcbset{ thmbox/.style={ breakable, enhanced, sharp corners=all, fonttitle=\bfseries\normalsize, fontupper=\normalsize\itshape, top=0mm, bottom=0mm, right=0mm, % colback=white, % colframe=white, % colbacktitle=white, %% in order to imitate effect of "enhanced jigsaw, boxrule=0pt". %% or put the following three lines in "extras unbroken={...}" frame engine=empty, interior titled engine=empty, %% every theorem has a title, so this is just for completeness interior engine=empty, extras broken={ frame engine=empty, interior titled engine=empty, interior engine=empty }, coltitle=black, attach boxed title to top left, boxed title style={empty, size=minimal, bottom=1.5mm}, overlay unbroken ={ \draw (title.south west)--(title.south east); \draw ([xshift=3.5mm]frame.north west)|-% (frame.south east)--(frame.north east);}, overlay first={ \draw (title.south west)--(title.south east); \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west); \draw (frame.north east)--(frame.south east);}, overlay middle={ \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west); \draw (frame.north east)--(frame.south east);}, overlay last={ \draw ([xshift=3.5mm]frame.north west)|-% (frame.south east)--(frame.north east);}, }, S/.style={thmbox, overlay unbroken ={ \draw (title.south west)--(title.south east); \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);}, overlay first={ \draw (title.south west)--(title.south east); \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);}, overlay middle={ \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);}, overlay last={ \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);}, }, L/.style={thmbox, overlay unbroken ={ \draw (title.south west)--(title.south east); \draw ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);}, overlay first={ \draw (title.south west)--(title.south east); \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);}, overlay middle={ \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);}, overlay last={ \draw ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);}, }, LQ/.style={thmbox, overlay unbroken ={ \draw (title.south west)--(title.south east); \draw ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west); \node[anchor=east] at (frame.south east) {$\square$};}, overlay first={ \draw (title.south west)--(title.south east); \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);}, overlay middle={ \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);}, overlay last={ \draw ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west); \node[anchor=east] at (frame.south east) {$\square$};}, },
}

\newtcbtheorem[]{tcbthmbox}{Theorem}{thmbox}{theo} \newtcbtheorem[]{tcbSthmbox}{Theorem}{thmbox,S}{theo} \newtcbtheorem[]{tcbLthmbox}{Theorem}{thmbox,L}{theo} \newtcbtheorem[]{proof}{Démonstration}{thmbox,LQ}{theo}

\begin{document}

\begin{tcbthmbox}{First result}{} \lipsum[3] \end{tcbthmbox}

\begin{tcbSthmbox}{Important}{} \lipsum[2] \end{tcbSthmbox}

\begin{tcbLthmbox}{Final}{} \lipsum[1] \end{tcbLthmbox}

\begin{proof}{Proof}{} \lipsum[1] \end{proof} \end{document}

muzimuzhi Z
  • 26,474
1

Turns out the answer is to read the docs :)

Typically, the frame engine fills the complete box area with color and the other engines fill certain areas with other colors. [...] For certain boxes, a more delicate procedure is needed. E.g., if the box should be translucent, an already painted area cannot be made unpainted. Therefore, more elaborate frame engines saw holes into the frame where the interior area and optionally the title area will be painted. The resulting skins are called jigsaw skins.

So one just needs to use jigsaw box:

\documentclass{article}
\usepackage{xcolor}
\usepackage{pagecolor}
\pagecolor{yellow}
\usepackage[most]{tcolorbox}
\usepackage{kantlipsum}

\begin{document}

\begin{tcolorbox}[ enhanced jigsaw, breakable, opacityback=0, ] This is a \textbf{tcolorbox}. \kant[1-5] \end{tcolorbox}

\end{document}

enter image description here

  • +1 This is great! There is one problem though, that if the frame rule has zero width (say by adding boxrule=0pt to your example), then the outline of the frame still displays. Not sure if this is a pdf artifact or intended, but it is relevant in the thmbox example I mentioned since the frame is partially hidden – mbert Jan 03 '24 at 14:23
  • @mbert I think viewer issue. I can reproduce your problem in poppler-based viewers, but in e.g. mac preview, it works fine. – samcarter_is_at_topanswers.xyz Jan 03 '24 at 14:25
  • (and I still think you should accept your answer :) – samcarter_is_at_topanswers.xyz Jan 03 '24 at 14:26
  • Interesting. It shows in poppler and acrobat but not in pdf.js or pdfxchange. Thanks for identifying the issue! – mbert Jan 03 '24 at 14:30
  • In fact \tikz\draw[line width=0pt](0,0)--(4,0); produces a line in all pdf viewers I've tried. I wonder if this is intended behavior – mbert Jan 03 '24 at 20:20
  • @mbert pdfviewer try to be clever, most of them do some fancy stuff like "thin line enhancement" and whatever they call their features. I'm sure this is often useful, but sometimes not so much. – samcarter_is_at_topanswers.xyz Jan 03 '24 at 20:55