`Tikz` 是否只能在 `standalone` 下使用,而不能在 `report` 下使用?

`Tikz` 是否只能在 `standalone` 下使用,而不能在 `report` 下使用?

这很简短回答演示如何使用以下方法程序化地弄脏任何字体

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{fadings,decorations}
\renewcommand*\sfdefault{ugq}
\usepackage[T1]{fontenc}

\def\smudgeText#1#2{%
  \begin{tikzfadingfrompicture}[name=.]
    \node [text=transparent!0, name=@] {#1};
    \clip (@.south west) rectangle (@.north east);
    \pgfpointdiff{\pgfpointanchor{@}{south west}}{\pgfpointanchor{@}{north east}}%
    \pgfgetlastxy\smudgewidth\smudgeheight
    \pgfmathparse{int(veclen(\smudgewidth,\smudgeheight)+1)}\let\n=\pgfmathresult
    \foreach \i in {1,...,\n}
      \path [draw=transparent, line width=rnd, line cap=round] (rand*\smudgewidth/2,rand*\smudgeheight/2) -- ++(135+rand*10:\smudgeheight/2);
  \end{tikzfadingfrompicture} 
  \begin{tikzpicture}
    \path [path fading=., fit fading=false, fading transform={shift=(@.center)}, fill=#2]
     (@.south west) rectangle (@.north east);
  \end{tikzpicture}%
}
\begin{document}

\begin{tikzpicture}
  \node [rotate=0] {\smudgeText{\Huge\sffamily\bfseries BE \emph{VERY} AFRAID}{black}};
\end{tikzpicture}

\end{document}

这是否意味着Tikz在 just 下可用standalone,而在 下则不可用report

例如,我该如何将上述内容扩展为下面的结果?

使用 tikz 报告

答案1

改编

  • 当然,你可以tikz独立于类使用,因此只需将其更改为report
  • 添加\usepackage{tikz}(因为它之前已通过选项导入[tikz]
  • 使用foreach循环多次创建同一节点

结果

在此处输入图片描述

代码

\documentclass{report}

\usepackage{tikz}

\usetikzlibrary{fadings,decorations}
\renewcommand*\sfdefault{ugq}
\usepackage[T1]{fontenc}

\def\smudgeText#1#2{%
  \begin{tikzfadingfrompicture}[name=.]
    \node [text=transparent!0, name=@] {#1};
    \clip (@.south west) rectangle (@.north east);
    \pgfpointdiff{\pgfpointanchor{@}{south west}}{\pgfpointanchor{@}{north east}}%
    \pgfgetlastxy\smudgewidth\smudgeheight
    \pgfmathparse{int(veclen(\smudgewidth,\smudgeheight)+1)}\let\n=\pgfmathresult
    \foreach \i in {1,...,\n}
      \path [draw=transparent, line width=rnd, line cap=round] (rand*\smudgewidth/2,rand*\smudgeheight/2) -- ++(135+rand*10:\smudgeheight/2);
  \end{tikzfadingfrompicture} 
  \begin{tikzpicture}
    \path [path fading=., fit fading=false, fading transform={shift=(@.center)}, fill=#2]
     (@.south west) rectangle (@.north east);
  \end{tikzpicture}%
}
\begin{document}

\begin{tikzpicture}
    \foreach \i in {1, ..., 3} {
      \node [scale=\i*.5] at (0, \i*15mm) {\smudgeText{\Huge\sffamily\bfseries Don't panic!}{black}};
    }
\end{tikzpicture}

\end{document}

相关内容