我已经使用 TikZ 制作了一个图表,现在我想对某些节点应用阴影,但我似乎不知道如何做到这一点。
这不起作用:
\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}
答案1
正如评论中指出的,这shading angle
需要是最后一个定义。
在示例中,我matrix of math nodes
仅使用了不同的方法来实现相同的目标:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
mymx/.style={ matrix of math nodes, nodes in empty cells,
row sep=3mm, column sep=2cm,
nodes={ minimum size=.7cm, draw, circle,
font=\sffamily\Large\bfseries, inner sep=0.05cm } },
sh/.style={ shade, shading=axis, left color=red, right color=green,
shading angle=45 } }
\begin{document}
\begin{tikzpicture}
\matrix[mymx,row 2/.style={every node/.append style=sh}] (mx) {
x_1 & x_2 & x_3 \\
&&\\[5mm]
&&\\
};
\draw (mx-1-1) -- (mx-2-1) -- (mx-3-1) -- (mx-3-2) -- (mx-3-3) -- (mx-2-3) -- (mx-1-3)
(mx-3-2) -- (mx-2-2) -- (mx-1-2) ;
\end{tikzpicture}
\end{document}