我正在为一个项目使用 Tikz 海报。我正在使用自定义命令\fadingtext
来实现渐变效果。当我使用时\title{ProjectTitle}
,编译结果是一个标准标题。但是当我使用时,\title{\fadingtext{ProjectTitle}}
顶部会被部分切断。我尝试过替换标题,但它仍然不受影响。使用此命令时字体也会发生变化。
\documentclass[17pt,a2paper,portrait]{tikzposter}
\usepackage[utf8]{inputenc}
\usepackage[export]{adjustbox}
\usepackage{tikz}
\usetikzlibrary{fadings}
\definecolor{UniBlue}{HTML}{0053A1}
\definecolor{CW2LightPink}{HTML}{FF3AB7}
\definecolor{CW2DarkPink}{HTML}{A00066}
\newcommand\fadingtext[2][]{%
\begin{tikzfadingfrompicture}[name = fading letter]
\node[text = transparent!0, inner xsep = 0pt, outer xsep = 0pt] {#2};
\end{tikzfadingfrompicture}%
\begin{tikzpicture}[baseline = (textnode.base)]
\node[inner sep = 0pt, outer sep = 0pt] (textnode) {\phantom{#2}};
\shade[path fading = fading letter, fading text, #1, fit fading = false]
(textnode.south west) rectangle (textnode.north east);%
\end{tikzpicture}%
}
\tikzset{fading text/.style = {left color = CW2LightPink, right color = CW2DarkPink}}
\title{\fadingtext{Modelling a Tennis Ball}}
%\title{Modelling a Tennis Ball}
\author{JKS}
\begin{document}
\maketitle
\end{document}
答案1
fit fading=false
防止淡入淡出缩放,但仍会进行转换。在这里,我使用了一个技巧,通过添加一个额外的圆圈来对齐中心\draw[transparent!100] (0,0) circle[radius=10];
。我很乐意学习其他方法。
\documentclass[17pt,a2paper,portrait]{tikzposter}
\usepackage{tikz}
\usetikzlibrary{fadings}
\newcommand\fadingtext[2][]{%
\begin{tikzfadingfrompicture}[name=fading letter]
\node[transparent!0, anchor=base] {#2};
\draw[transparent!100] (0,0) circle[radius=10];
\end{tikzfadingfrompicture}%
\begin{tikzpicture}[baseline]
\node[anchor=base, inner sep=0] (textnode) {\phantom{#2}};
\draw[path fading=fading letter, fading text, #1, fit fading=false] (textnode.south west) rectangle (textnode.north east);%
\end{tikzpicture}%
}
\tikzset{fading text/.style = {left color=red, right color=green}}
\title{\fadingtext{Modelling a Tennis Ball}}
%\title{Modelling a Tennis Ball}
\author{JKS}
\begin{document}
\maketitle
\end{document}
编辑:比绘制圆圈更好的方法是将其用作边界框:
\useasboundingbox (0,0) circle[radius=10];