I have made a graph with TikZ and now I would like to apply a shading to some of the nodes but I can't seem to find out how to do that.
This doesn't work:
\documentclass{article}
\usepackage{tikz}
\tikzset{every node/.append style={minimum size=.7cm, draw,circle,font=\sffamily\Large\bfseries,inner sep=0.05cm}}
\begin{document}
\begin{tikzpicture}[sh/.style={shade,shading=axis,shading angle=45,left color=red,right color=green}]
\node (x1) {$x_1$};
\node[node distance=3cm,right of=x1] (x2) {$x_2$};
\node[node distance=3cm,right of=x2] (x3) {$x_3$};
\node[node distance=1cm,below of=x1] (1) [sh] {};
\node[node distance=1cm,below of=x2] (2) [sh] {};
\node[node distance=1cm,below of=x3] (3) [sh] {};
\node[node distance=1.5cm,below of=1] (4) {};
\node[node distance=1.5cm,below of=2] (5) {};
\node[node distance=1.5cm,below of=3] (6) {};
\foreach \from/\to in {x1/1,x2/2,x3/3,1/4,2/5,3/6,4/5,5/6} \draw (\from) -- (\to);
\end{tikzpicture}
\end{document}
Best Answer
As noted in the comments, the
shading angle
needs to be the last definition.In the example I've used a
matrix of math nodes
just to show a different way to achieve the same goal: