By 鱼香肉丝没有鱼先生@u19850
我拿l3写一个试试
\documentclass{ctexart}
\usepackage{xcolor}
\ExplSyntaxOn
% #1 start-color #2: end-color #3: text
\cs_new:Npn \__gradien_text:nnn #1#2#3
{
\tl_set:Nn \l_tmpa_tl { #3 }
\int_set:Nn \l_tmpa_int { \tl_count:N \l_tmpa_tl }
\int_step_inline:nn { \l_tmpa_int } {
\textcolor{#2!\fp_eval:n{##1 * 100/\l_tmpa_int}!#1}{\tl_item:Nn \l_tmpa_tl {##1}}
\allowbreak
}
}
\NewDocumentCommand{\gradienttext}{mm+m}{\__gradien_text:nnn{#1}{#2}{#3}}
\ExplSyntaxOff
\begin{document}
\gradienttext{red}{blue}{劳仑衣普桑,认至将指点效则机,最你更枝。想极整月正进好志次回总般,段然取向使张规军证回,世市总李率英茄持伴。}
\end{document}
用户「LaTex新手心态」给出的基于gradient-text
的方案:
\documentclass{article}
\usepackage{gradient-text}
\begin{document}
\begin{center}
{\Huge\bfseries
\gradientRGB{ZHONGGUO GONGCHANDANG}{230,0,0}{135,0,0}
\gradientRGB{WANSUI}{230,0,0}{135,0,0}\par
}
\end{center}
\end{document}
小插曲:事实上,gradient-text
内部实现和「Method1」如出一辙,均为「逐字渐变」
同样是By 鱼香肉丝没有鱼先生 @u19850:
用tikz
,可以封装一下,小规模使用,不考虑换行,应该还行
\documentclass[margin=2cm]{standalone}
\usepackage{tikz,ctex}
\usetikzlibrary{decorations.text,math}
\begin{document}
\begin{tikzpicture}[
decoration = {
text effects along path,
text = {劳仑衣普桑,认至将指点效则机,最你更枝。},
text effects/.cd,
character count=\i, character total=\n,
characters = {
text along path,
evaluate = {\c=\i/\n*100;},
text = orange!\c!blue, scale=1
}
}
]
\path [decorate] (0,0) to (8,0);
\end{tikzpicture}
\end{document}
texhigh
宏包:在其编译内容中使用效果可以实现真正的渐变:
由于暂缺texhigh
的用户文档,目前我的测试举步维艰😭😭😭。实现「真正的文字渐变」的最佳实践是什么?是否有可能脱离「texhigh」提取出一个轻量级的命令?
后者似乎是texhigh
用的方式:
% texhigh.prelude.ths Line101
\@ifpackageloaded{tikz}{\@texhighload@tikztrue}{}
\newbox\texhigh@picturebox
\if@texhighload@tikz
\RequirePackage{tikz}
\usetikzlibrary{shadings}
\usetikzlibrary{fill.image}
\protected\def\texhigh@shadetext#1#2{%
\setbox\texhigh@picturebox=\hbox{{\texhigh@pdfliteral{7 Tr }#2}}%
\tikz[baseline=0,line width=0pt]\path\pgfextra{\rlap{\copy\texhigh@picturebox}}
[#1] (0,-\dp\texhigh@picturebox) rectangle (\wd\texhigh@picturebox,\ht\texhigh@picturebox);}
\tikzset{texhigh/.is family,
texhigh/gradient primitive/.style={left color=blue,right color=cyan},
texhigh/gradient ?/.style={left color=red,right color=blue},
texhigh/gradient-style/.style={texhigh/gradient #1}}
\THSaveStyle{tikz.gradient}{%
\THSetClassCS{latex}{\texhigh@underline{\THcolor{purple}\bfseries#1#2}}
\THSetClassCS{primitive}
{\texhigh@shadetext{texhigh/gradient-style=primitive}{\bfseries #1#2}}%
\THSetClassCS{?}{\texhigh@shadetext{texhigh/gradient-style=?}{#1#2}}%
}