在 tcolorbox 的整个内容上方对角放置、重复的水印文本

在 tcolorbox 的整个内容上方对角放置、重复的水印文本

考虑一下这个MWE:

\documentclass[table]{standalone}
\usepackage{graphicx, polyglossia, lipsum}
\usepackage[most]{tcolorbox}

\newtcolorbox{mybox}[2][]{%
  enhanced,
  before upper=\setlength{\parskip}{\bigskipamount},
  colframe=black,
  boxrule=2mm,
  bottomrule=8mm,
  colbacktitle=black,
  fonttitle=\bfseries\centering,
  overlay app={%
    \node[white, anchor=south, text width=.95\textwidth] at (frame.south) {Some footer text};},
  title=#2,#1}

\newcommand{\xxbody}{
  \lipsum[2]

  \noindent\includegraphics[width=\textwidth]{example-image-golden}

  \lipsum[3]
}

\newcommand{\xxheading}{%
  Heading
}

\begin{document}

\begin{mybox}{\LARGE \xxheading{}}

  \xxbody{}

\end{mybox}

\end{document}

我想添加一些水印文本,比如“草稿”。文本应从文本框的左下角延伸到右上角,并与该线平行。因此,“草稿”将多次出现。文本的角度将随着文本框变小或变大而改变。

它应该位于包括图像在内的整个内容之上。

可以做到吗?怎样做?

答案1

像这样?

在此处输入图片描述

\documentclass[table]{standalone}
\usepackage{graphicx, polyglossia, lipsum}
\usepackage[most]{tcolorbox}
\usetikzlibrary{patterns, calc}

\tcbset{ribbon/.style={finish={%
\begin{tcbclipframe}
\path (frame.south west) -- (frame.north east) let \p1=($(frame.north east)-(frame.south west)$) in node[red, midway, sloped, font=\Huge\bfseries, align=center, text width={veclen(\x1,\y1)}] {Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft};
    \end{tcbclipframe}}}}

\newtcolorbox{mybox}[2][]{%
  enhanced,
  before upper=\setlength{\parskip}{\bigskipamount},
  colframe=black,
  boxrule=2mm,
  bottomrule=8mm,
  colbacktitle=black,
  fonttitle=\bfseries\centering,
  overlay app={%
    \node[white, anchor=south, text width=.95\textwidth] at (frame.south) {Some footer text};}
    overlay={
    \path (frame.south west)--(frame.north east) node[red, draw, midway, sloped, font=\Large] {Draft\\ Draft\\ Draft};},
  title=#2,#1}

\newcommand{\xxbody}{
  \lipsum[2]

  \noindent\includegraphics[width=\textwidth]{example-image-golden}

  \lipsum[3]
}

\newcommand{\xxheading}{%
  Heading
}

\begin{document}

\begin{mybox}[ribbon]{\LARGE \xxheading{}}

  \xxbody{}

\end{mybox}

\end{document}

更新:

如果只覆盖部分文本,tcbclipinterior可以使用。如果要覆盖全部内容,则需要更长的文本或更长的文本和更大的比例。

如果要确保覆盖所有内容,可以绘制多条独立的线,而不是绘制唯一的节点。

\documentclass[table]{standalone}
\usepackage{graphicx, polyglossia, lipsum}
\usepackage[most]{tcolorbox}
\usetikzlibrary{patterns, calc}

\tcbset{ribbon/.style={finish={%
\begin{tcbclipinterior}
\path (frame.south west) -- (frame.north east) let \p1=($(frame.north east)-(frame.south west)$) in node[red, midway, sloped, font=\Huge\bfseries, align=center, text width={veclen(\x1,\y1)}, scale=2, opacity=.5] {Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft Draft};
    \end{tcbclipinterior}}}}

\newtcolorbox{mybox}[2][]{%
  enhanced,
  before upper=\setlength{\parskip}{\bigskipamount},
  colframe=black,
  boxrule=2mm,
  bottomrule=8mm,
  colbacktitle=black,
  fonttitle=\bfseries\centering,
  overlay app={%
    \node[white, anchor=south, text width=.95\textwidth] at (frame.south) {Some footer text};}
    overlay={
    \path (frame.south west)--(frame.north east) node[red, draw, midway, sloped, font=\Large] {Draft\\ Draft\\ Draft};},
  title=#2,#1}

\newcommand{\xxbody}{
  \lipsum[2]

  \noindent\includegraphics[width=\textwidth]{example-image-golden}

  \lipsum[3]
}

\newcommand{\xxheading}{%
  Heading
}

\begin{document}

\begin{mybox}[ribbon]{\LARGE \xxheading{}}

  \xxbody{}

\end{mybox}

\end{document}

在此处输入图片描述

相关内容