需要帮助让 tcolorbox 正确

需要帮助让 tcolorbox 正确

我正在尝试制作一个形状的盒子来容纳任意内容,并使用我tcolorbox从另一个问题改编的代码。到目前为止,我有:

\documentclass[20pt, a4paper]{article}

\usepackage{color}
\usepackage{tcolorbox}
\usepackage{lipsum}

\tcbuselibrary{skins}
\usetikzlibrary{calc}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newtcolorbox{mybox}{
    left=15pt,
    top=15pt,
    bottom=15pt,
    right=15pt,
    skin=freelance,
    frame code={%
        \begin{pgfonlayer}{background}
            \draw[line width=4pt,color=purple,fill=purple]($(frame.north west) + (15pt, 0pt)$)
                -- (frame.north east)
                -- ($(frame.south east) + (0pt, 15pt)$)
                -- ($(frame.south east) + (-15pt, 0pt)$)
                -- (frame.south west)
                -- ($(frame.north west) + (0pt, -15pt)$)
                -- cycle;

        \end{pgfonlayer}
    },
}

\begin{document}

\begin{mybox}
\lipsum[1]
\end{mybox}

\end{document}

我希望用某种方式完全填充形成的形状,使其不超出线条,而是位于要显示的内容后面。使用该colback选项会创建一个圆角矩形框,该矩形框的颜色在点处超出线条,而在其他点处则未完全到达角落。但是,如果我尝试使用形状的填充选项,那么它要么被填充并遮挡文本,要么完全位于背景颜色框后面(取决于我将框架代码放在哪个层上)。

答案1

基本上,对于 必须采用相同的方法interior code,但需要调整顶点!

\documentclass[20pt, a4paper]{article}


\usepackage[skins]{tcolorbox}
\usepackage{lipsum}

\usetikzlibrary{calc}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newtcolorbox{mybox}{%
    left=15pt,
    top=15pt,
    bottom=15pt,
    right=15pt,
    skin=enhanced jigsaw,
    frame code={%
      \begin{pgfonlayer}{background}
        \draw[line width=4pt,color=purple,fill=purple]($(frame.north west) + (15pt, 0pt)$)
        -- (frame.north east)
        -- ($(frame.south east) + (0pt, 15pt)$)
        -- ($(frame.south east) + (-15pt, 0pt)$)
        -- (frame.south west)
        -- ($(frame.north west) + (0pt, -15pt)$)
        -- cycle;
      \end{pgfonlayer}
    },
    interior code={%
      \draw[line width=4pt,color=purple,fill=white!90!black]($(frame.north west) + (15pt, -4pt)$) -- ($(frame.north east) + (-4pt,-4pt)$) 
      -- ($(frame.south east) + (-4pt, 15pt)$)  
      -- ($(frame.south east) + (-15pt, 4pt)$)
      -- ($(frame.south west) + (4pt, 4pt)$)
      -- ($(frame.north west) + (4pt, -15pt)$)
      -- cycle;
    }
}

\begin{document}

\begin{mybox}
\lipsum[1]
\end{mybox}

\end{document}

在此处输入图片描述

相关内容