tcolorbox宏包overlay绘图透明度问题

发布于 2025-07-14 15:56:42
\documentclass{article}
\usepackage[UTF8]{ctex}
\usepackage[most]{tcolorbox}
\usetikzlibrary{patterns}
\usepackage{zhlipsum}
\begin{document}

\tcbset{
  frogbox/.style={
    enhanced,
    colback=green!10,
    colframe=green!65!black,
    enlarge top by=5.5mm,
    overlay={
      \foreach \x in {2cm, 3.5cm} {
        \begin{scope}[shift={([xshift=\x]frame.north west)}]
          \path[draw=green!65!black, fill=green!10, line width=1mm] (0,0) arc (0:180:5mm);
          \path[fill=black] (-0.2,0) arc (0:180:1mm);
        \end{scope}
      }
    }
  },
  ribbon/.style={
    overlay app={
      \path[
        fill=blue!75!white,
        draw=blue,
        double=white!85!blue,
        preaction={fill=blue!75!white},
        line width=0.1mm,
        double distance=0.2mm,
        pattern=fivepointed stars,
        pattern color=white!75!blue
      ]
      ([xshift=-1cm, yshift=-2cm]frame.north east)
      -- ++(-1,1)
      -- ++(-0.5,0)
      -- ++(1.5,-1.5)
      -- cycle;
    }
  }
}

\begin{tcolorbox}[frogbox, title=My title]
This is a \textbf{tcolorbox}.
\end{tcolorbox}

\begin{tcolorbox}[frogbox, ribbon, title=My title]
\zhlipsum[1-3]
\end{tcolorbox}

\end{document}

C5065BFC64AE4F75EA799597F41563D9.png

请教老师们,如何完全遮住文字?

查看更多

关注者
0
被浏览
68
1 个回答
Sagittarius Rover
Sagittarius Rover 16小时前
我要成为Typst糕手/(ㄒoㄒ)/~~

读文档第九章第四节 drawing scheme

image.png

改用finish而不是overlay app即可。

另外,既然文字需要被「装饰」遮盖住,那这个文字被排出来的作用是什么呢? 建议提供一下具体的应用场景。

\documentclass{article}
\usepackage[UTF8]{ctex}
\usepackage[most]{tcolorbox}
\usetikzlibrary{patterns}
\usepackage{zhlipsum}
\begin{document}

\tcbset{
  frogbox/.style={
    enhanced,
    colback=green!10,
    colframe=green!65!black,
    enlarge top by=5.5mm,
    overlay={
      \foreach \x in {2cm, 3.5cm} {
        \begin{scope}[shift={([xshift=\x]frame.north west)}]
          \path[draw=green!65!black, fill=green!10, line width=1mm] (0,0) arc (0:180:5mm);
          \path[fill=black] (-0.2,0) arc (0:180:1mm);
        \end{scope}
      }
    }
  },
  ribbon/.style={
    finish={
      \path[
        fill=blue!75!white,
        draw=blue,
        double=white!85!blue,
        preaction={fill=blue!75!white},
        line width=0.1mm,
        double distance=0.2mm,
        pattern=fivepointed stars,
        pattern color=white!75!blue
      ]
      ([xshift=-0.2mm, yshift=-2.02cm]frame.north east)
      -- ++(-2,2)
      -- ++(-0.5,0)
      -- ++(2.5,-2.5)
      -- cycle;
    }
  }
}

\begin{tcolorbox}[frogbox, ribbon, title=My title]
\zhlipsum[1]
\end{tcolorbox}

\end{document}

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览