具有空/隱藏內部和非空框架的易碎 tcolorbox

具有空/隱藏內部和非空框架的易碎 tcolorbox

我想定義一個易碎的 tcolorbox,其內部不包含顏色或其他繪圖程式碼,因此顯示其後面的任何顏色。tcolorboxskins有選項interior emptyinterior hidden來控制內部的繪製,儘管我很難理解這些鍵與相應的frame empty和之間的交互作用frame hidden。我希望以前的鑰匙打印圍繞盒子內容物的框架,而不對內部進行任何處理,但盒子卻打印有深灰色背景。

這個答案frame empty,我發現我們可以透過設定兩者然後interior empty用 繪製框架來解決這個問題borderline。這適用於未損壞的盒子,但如果盒子損壞了,則frame emptyinterior empty鍵似乎會被忽略,並且 tcolorbox 預設值會生效。

\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

我可能誤解了「框架」和「內部」的真正含義,但是有沒有辦法製作一個內部空的易碎的 tcolorbox ?

編輯

正如 samcarter_is_at_topanswers.xyz 在評論中指出的那樣,「框架」是框架後面的填充矩形,而不是圍繞它繪製的線。這解釋了interior empty和 的輸出interior hidden

我還發現與一般情況下breakable不能很好地互動:frame emptyinterior empty

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

這會在損壞時重置框架和內部預設值。

對於上下文,我正在嘗試適應這個答案用於模仿thmbox與 tcolorbox 使用頁面背景顏色,而不是預設背景顏色white,因為這是 thmbox 的行為。

答案1

事實證明答案是閱讀文件:)

通常,框架引擎會用顏色填充整個框區域,而其他引擎則用其他顏色填充某些區域。 [...] 對於某些盒子,需要更精細的程序。例如,如果盒子應該是半透明的,則已經塗漆的區域不能不塗漆。因此,更複雜的框架引擎在框架上鋸了一些孔,其中將繪製內部區域和可選的標題區域。由此產生的皮膚稱為拼圖皮膚。

所以我們只需要使用拼圖盒:

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

在此輸入影像描述

答案2

您可以將其設定為透明,而不是實際使 tcolorbox 透明透過將其著色為與頁面相同的顏色來透明:

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

在此輸入影像描述

答案3

雖然frame emptyinterior empty在與 一起使用時不會按預期工作breakable,但如果使用該extras鍵,它們就會起作用。這樣我們就可以用 來偽造框架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}

易碎的盒子

答案4

對於上下文,我正在嘗試適應這個答案用於模仿thmbox與 tcolorbox 使用頁面背景顏色,而不是預設背景顏色white,因為這是 thmbox 的行為。

看來你需要

\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
        },
        % ...
    }
}

在此輸入影像描述

完整示例,基於鏈接@伊格納西的回答:

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

相關內容