Example: Fading text

Published 2014-07-30 | Author: Elke Schubert

Here we would like to add a color fading to single characters and whole text. It should be possible to use the shaded text within normal text, without an additional border and aligned at the normal text base line.

We define a command \fadingtext[<color options>]{<text>} and furthermore a style fading text for defining preset colors.

\phantom is used to define a place holder node, we use the same node for aligning at the surrounding text’s base line, and this node is then shaded with the previously defined fading.

The example shows, how the style is set. Note, that the middle color has to be set as the last one. So, if you change a color later, re-set the middle color (or it’s removed).

This example was written by Elke Schubert on TikZ.de.

Download as: [PDF] [TEX]

Fading text

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

% Fading text
% Author: Elke Schubert
\tikzset{fading text/.style={}}

  \begin{tikzfadingfrompicture}[name = fading letter]
    \node[text = transparent!0, inner xsep = 0pt, outer xsep = 0pt] {#2};
  \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);% 

\tikzset{fading text/.style = {left color = red, right color = red!50!blue,
  middle color = green}}
\fbox{\scalebox{4}{\fadingtext[left color = green, right color = red]{$4$}}}
For testing the alignment: \fadingtext{Here is a colored sample sentence.} 

\noindent\fadingtext[top color = orange, bottom color = purple,
  middle color=.]{\parbox[b]{\linewidth}{\strut\lipsum[1]}}


Adding comments is currently not enabled.