彩虹色的文本字符串

彩虹色的文本字符串

是否可以在乳胶中创建以下效果?

波浪冲刺.ppt

核心是每个单词都有不同的颜色,而不是使用阴影,因为阴影会使文本混乱。

如果使用 javascript 和 svg 来完成,那就没问题了。

这张图片感谢 Celeste......我正在尝试使用 dvisvgm 将 wavedash.ppt 移植到 latex,但有点卡住了。

答案1

你可以使用gradient-text这一调整

\documentclass{article}

% rainbow text (based on the gradient-text package)
\makeatletter
\ExplSyntaxOn
\clist_new:N\l_gtext_First_clist
\clist_new:N\l_gtext_Last_clist
\int_new:N\l_gtext_MaxIndex_int
\int_new:N\l_gtext_Ratio_int
\newcommand{\gr@dient}[8]{
  \int_set:Nn\l_gtext_MaxIndex_int{\int_eval:n{\str_count:n{#1}}}
  \int_step_inline:nnn{1}{\l_gtext_MaxIndex_int}{
      \exp_args:Ne\str_if_eq:nnTF{\str_item:Nn{#1}{##1}}{~}{}{
        \int_set:Nn\l_gtext_Ratio_int{\int_eval:n{\l_gtext_Ratio_int+1}}
      }
        \color_select:nn{#8}{
          \int_eval:n{(\int_use:N\l_gtext_Ratio_int*#5+(\l_gtext_MaxIndex_int-##1)*#2)/\l_gtext_MaxIndex_int},
          \int_eval:n{(\int_use:N\l_gtext_Ratio_int*#6+(\l_gtext_MaxIndex_int-##1)*#3)/\l_gtext_MaxIndex_int},
          \int_eval:n{(\int_use:N\l_gtext_Ratio_int*#7+(\l_gtext_MaxIndex_int-##1)*#4)/\l_gtext_MaxIndex_int}
      }\str_item:Nn{#1}{##1}
  }
}

\NewDocumentCommand\gradient{mmmm}{{
  \clist_set:Nn\l_gtext_First_clist {#3}
  \clist_set:Nn\l_gtext_Last_clist {#4}
  \gr@dient{#2}
  {\clist_item:Nn\l_gtext_First_clist{1}}
  {\clist_item:Nn\l_gtext_First_clist{2}}
  {\clist_item:Nn\l_gtext_First_clist{3}}
  {\clist_item:Nn\l_gtext_Last_clist{1}}
  {\clist_item:Nn\l_gtext_Last_clist{2}}
  {\clist_item:Nn\l_gtext_Last_clist{3}}
  {#1}
}}
\ExplSyntaxOff

\NewDocumentCommand\gradientRGB{mmm}{
  \gradient{RGB}{#1}{#2}{#3}
}

\NewDocumentCommand\gradientHSB{mmm}{
  \gradient{HSB}{#1}{#2}{#3}
}
\makeatother

\begin{document}

\gradient{HSB}{Colour is all.}{0,240,200}{240,240,200}

\gradient{RGB}{Colour is all.}{255,0,0}{0,0,255}

\gradientHSB{Colour is all.}{0,240,200}{240,240,200}

\gradientRGB{Colour is all.}{255,0,0}{0,0,255}

\end{document}

在此处输入图片描述

答案2

这是 TiZ 解决方案改编自我之前的回答,例如,这可能与 Beamer 有关。

\documentclass[border=10pt,multi,tikz]{standalone}
% ateb: https://tex.stackexchange.com/a/701971/
% addaswyd o fy ateb: https://tex.stackexchange.com/a/344548/
\usetikzlibrary{fadings}
\usepackage{xparse}
\pgfdeclarehorizontalshading{rainbow}{100bp}{%
  rgb(0bp)=(1,0,0);
  rgb(26bp)=(1,0,0);
  rgb(33bp)=(1,.5,0);
  rgb(40bp)=(1,1,0);
  rgb(47bp)=(0,1,0);
  rgb(54bp)=(0,1,1);
  rgb(61bp)=(0,0,1);
  rgb(68bp)=(1,0,1);
  rgb(75bp)=(.5,0,.5);
  rgb(100bp)=(.5,0,.5)}
\begin{tikzfadingfrompicture}[name=wavedashing]
  \node [text=transparent!0, inner sep=0pt] {\sffamily\bfseries\selectfont Wavedashing and You};
\end{tikzfadingfrompicture}%
\begin{document}
\begin{tikzpicture}
  \shade [shading=rainbow, path fading=wavedashing, fit fading=false] (-18mm,-10mm) rectangle (18mm,10mm);
\end{tikzpicture}
\end{document}

Wavedashing 和你

答案3

在这里调整我的褪黑答案:如何在一定长度之后“淡出”文本?,改变整个字符串长度的颜色:

\documentclass{article}
\usepackage{xcolor,ifthen}
\newcounter{tmpcounter}
\newlength\cumlength
\newlength\critlength
\newlength\tmplength
\newcount\mynum
\newcount\myden
\makeatletter
\newcommand\ColorShift[3]{\colorlet{cfrom}{#1}\colorlet{cto}{#2}\sbox0{#3}%
  \critlength=\wd0\relax\cumlength=0pt\relax%
  \def\cumstring{}\fahelp{\critlength}{#3}}
\newcommand\fahelp[2]{\prefahelper#2 \relax\fahelper#2\relax}
\def\prefahelper#1#2 #3\relax{\gdef\wordremaining{#1#2}}
\def\fahelper#1#2\relax{%
  \global\protected@edef\cumstring{\cumstring#1}%
  \ifthenelse{\equal{#1}{\wordremaining}}{%
    \global\protected@edef\cumstring{\cumstring\ }}{}%
  \setbox0=\hbox{\cumstring}%
  \tmplength=.01\critlength\relax%
  \mynum=\wd0\relax%
  \myden=\tmplength\relax%
  \divide\mynum by\myden%
  \setcounter{tmpcounter}{\numexpr100-\the\mynum}%
  \ifnum\thetmpcounter<0\setcounter{tmpcounter}{0}\fi%
  \textcolor{cfrom!\thetmpcounter!cto}{#1}%
  \ifthenelse{\equal{#1}{\wordremaining}}{\ }{}%
  \ifdim\wd0<\critlength%
    \ifx\relax#2\relax\else\fahelp{\critlength}{#2}\fi%
  \fi%
}
\makeatother
\begin{document}
\bfseries\sffamily
\ColorShift{cyan}{yellow!80!red}{Test}%

\ColorShift{red}{blue}{Testing whether this shifts color}%

\ColorShift{black}{red}{This is a very long multi-line test
This is a very long test This is a very long test
This is a very long test This is a very long test}
\end{document}

在此处输入图片描述

相关内容