答案1
你可以用任何东西给文本“上色”,包括外部图形。这可以通过fadings
库来实现,例如这里和这里。我下载了您的图形并将其调用GoldLeaf.jpg
。该图形用于宏\ShadeText
,该宏执行路径淡入淡出并调整图形大小以适合文本。如果您想在中使用结果tikzpicture
,请使用\savebox
第二个示例中所示的。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings,calc}
\newcommand{\ShadeText}[2][]{%
\begin{tikzfadingfrompicture}[name=temp]
\node[transparent!0] {#2};
\end{tikzfadingfrompicture}%
\tikz[baseline=(X.base)]{\node[inner sep=0pt,outer sep=0pt] (X)
{\phantom{#2}};
\path[path fading=temp,fit fading=false,overlay] let
\p1=($(X.north east)-(X.south west)+(0.3,0.3)$) in (X.center)
node{\includegraphics[width=\x1,height=\y1]{GoldLeaf.jpg}};}%
}
\newsavebox\WhatEver
\begin{document}
\ShadeText{\sffamily\Large\bfseries I'm a title}
\bigskip
\savebox\WhatEver{\ShadeText{\sffamily\Large\bfseries I'm a title}}
\begin{tikzpicture}
\fill (0,0) rectangle (6,3) node[midway,scale=2]{\usebox\WhatEver};
\end{tikzpicture}
\end{document}
如果您不想修改图片的纵横比,您可以使用以下方法。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings,calc}
\newcommand{\ShadeText}[2][]{%
\begin{tikzfadingfrompicture}[name=temp]
\node[transparent!0] {#2};
\end{tikzfadingfrompicture}%
\tikz[baseline=(X.base)]{\node[inner sep=0pt,outer sep=0pt] (X)
{\phantom{#2}};
\path[overlay] node[opacity=0] (img) {\includegraphics{GoldLeaf.jpg}}
[path fading=temp,fit fading=false,overlay]
let \p1=($(X.north east)-(X.south west)+(0.3,0.3)$),
\p2=($(img.north east)-(img.south west)+(0.3,0.3)$) in
(X.center) node{\pgfmathsetmacro{\myscale}{max(\x1/\x2,\y1/\y2)}%
\includegraphics[scale=\myscale]{GoldLeaf.jpg}};
}%
}
\newsavebox\WhatEver
\begin{document}
\ShadeText{\sffamily\Large\bfseries I'm a title}
\bigskip
\savebox\WhatEver{\ShadeText{\sffamily\Large\bfseries I'm a title}}
\begin{tikzpicture}
\fill (0,0) rectangle (6,3) node[midway,scale=2]{\usebox\WhatEver};
\end{tikzpicture}
\end{document}
附录:当然,除了\node
对象之外,您还可以使用它。这是一个非常快速编写的环境,说明了这一点。环境的主体是您想要“着色”的东西,主要参数是您要用于“着色”的图形文件的名称(技术上正确的术语是什么?),可选参数是一些 pgf 键,其用法已说明。为了完成这个附录,fading transform
我从中学到的关键这个非常好的答案,起到了重要作用。samcarter 的评论也对本文大有裨益,他指出,金色的叶子看起来几乎和土拨鼠的皮毛一样美丽。;-)
\documentclass{article}
\usepackage{environ}
\usepackage{tikz}
\usepackage{tikzlings}
\usetikzlibrary{fadings,calc,decorations.pathmorphing}
\NewEnviron{ShadeTikZ}[2][]{\begin{tikzfadingfrompicture}[name=temp]%
\begin{scope}[transparent!0,#1]
\BODY
\end{scope}
\end{tikzfadingfrompicture}%
\tikz[#1]{\begin{scope}[local bounding box=X,opacity=0]%
\BODY
\end{scope}
\path[overlay] (X.center) node[opacity=0,inner sep=0pt] (img) {\includegraphics{#2}}
[path fading=temp,fit fading=false,fading transform={shift={(X.center)}}]
let \p1=($(X.north east)-(X.south west)+(0.3,0.3)$),
\p2=($(img.north east)-(img.south west)+(0.3,0.3)$) in
(X.center) node[inner sep=0pt,anchor=center]{\pgfmathsetmacro{\myscale}{max(\x1/\x2,\y1/\y2)}%
\includegraphics[scale=\myscale]{#2}};
}%
}
\newsavebox\WhatEver
\begin{document}
\begin{ShadeTikZ}[baseline={(txt.base)}]{GoldLeaf.jpg}
\node[draw,thick,align=center,font=\sffamily\bfseries\Large] (txt)
{2019\\
Hibernation\\[0.5ex]
Awards};
\marmot[yshift=1cm]
\end{ShadeTikZ}
\bigskip
\savebox\WhatEver{\begin{ShadeTikZ}[baseline={(txt.base)}]{GoldLeaf.jpg}
\node[draw,thick,align=center,font=\sffamily\bfseries\Large] (txt)
{2019\\
Hibernation\\[0.5ex]
Awards};
\marmot[yshift=1cm]
\end{ShadeTikZ}}
\begin{tikzpicture}
\fill (0,0) rectangle (6,9) node[midway,scale=2]{\usebox\WhatEver};
\end{tikzpicture}
\end{document}