我想对某些文本(即章节/节标题)应用颜色渐变,我搜索了互联网,但找不到最小工作示例。这可以在 XeLaTeX 中实现吗?
我决定在这里问一下,认为社区中可能已经有人做过类似的事情。
答案1
以下示例来自 TikZ 2.10 手册 p237,似乎可以完成您描述的操作:
\begin{tikzfadingfrompicture}[name=tikz]
\node [text=transparent!20]
{\fontfamily{ptm}\fontsize{45}{45}\bfseries\selectfont Ti\emph{k}Z};
\end{tikzfadingfrompicture}
% Now we use the fading in another picture:
\begin{tikzpicture}
\fill [black!20] (-2,-1) rectangle (2,1);
\pattern [pattern=checkerboard,pattern color=black!30] (-2,-1) rectangle (2,1);
\shade[path fading=tikz,fit fading=false, left color=blue,right color=black]
(-2,-1) rectangle (2,1);
\end{tikzpicture}
稍加调整,您可以实现以下目标:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns}
\begin{document}
\newsavebox{\tempbox}
\newcommand\tikzsection[1]{%
\begin{tikzfadingfrompicture}[name=tikzsection]
\node [text=white] {\normalfont \Large \bfseries #1};
\end{tikzfadingfrompicture}
\begin{lrbox}{\tempbox}%
\begin{tikzpicture}
\node [text=white,inner sep=0pt,outer sep=0pt] (textnode) {\normalfont \Large \bfseries #1};
\shade[path fading=tikzsection,fit fading=false,left color=blue,right color=black]
(textnode.south west) rectangle (textnode.north east);
\end{tikzpicture}%
\end{lrbox}
% Now we use the fading in another picture:
\section{XX \usebox\tempbox{} XX}%
}
\tikzsection{First section}
Some text
\tikzsection{Second section}
Some text
\end{document}
产生