I need a single character in two colors. Figuring I could use the shadings
library of TikZ, I followed the manual (section 23.4.1, the TikZ example):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings,shadings}
\begin{document}
\begin{tikzfadingfrompicture}[name=mixed 4]
\node[text=transparent!0] {$4$};
\end{tikzfadingfrompicture}
\fbox{\tikz[scale=10]\shade[path fading=mixed 4,top color=orange,bottom color=purple]
(0,0) rectangle (2ex,2ex);}
\end{document}
However, the result is no good for two reasons:
- The surrounding box is far too large; it's not possible to use the
character in text of formulae. - Only the center part of the shading is visible in the character, rendering it almost invisible.
How can I make the shading apply only to the character, without any surrounding space?
If it's easier, I can also do without the shading but a hard change of colors, that is something like this (gimped):
The angle of the separation line is not that important.
Best Answer
Here is another suggestion:
You can use this to color text:
Code:
Here is an additional suggestion with a sharp border between the two colors:
Code:
With TikZ version 3.0 you can also use the
transparency group=knockout
option. Then it is possible to shade diagonal. But AFAIK only Acrobat Reader shows the correct result, because only this viewer is able to handle transparencies.Code: