阴影角度对节点没有影响

阴影角度对节点没有影响

我正在尝试创建一个一半颜色一半颜色的节点,并遵循这个答案中提出的想法:https://tex.stackexchange.com/a/343674/42861

但是,无论我分配什么shading angle,我总是得到一个垂直分割节点。

在此处输入图片描述

我的所有节点都需要相同的分割,所以我决定定义一个节点样式:

\tikzstyle{dc-node}=[node-base, shading angle=45, double color fill={AntiqueWhite}{LightBlue}]

node-base我的所有节点的基本样式如下:

\tikzstyle{node-base}=[circle, draw, align=center, font=\footnotesize, minimum size=1.3cm]

包含的图片使用以下代码生成:

\documentclass[svgnames]{standalone}

\usepackage{tikz}
\usepackage{lmodern}
\usetikzlibrary{shadows}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning}
\usetikzlibrary{shadings}
\tikzset{
    double color fill/.code 2 args={
        \pgfdeclareverticalshading[%
            tikz@axis@top,tikz@axis@middle,tikz@axis@bottom%
        ]{diagonalfill}{100bp}{%
            color(0bp)=(tikz@axis@bottom);
            color(50bp)=(tikz@axis@bottom);
            color(50bp)=(tikz@axis@middle);
            color(50bp)=(tikz@axis@top);
            color(100bp)=(tikz@axis@top)
        }
        \tikzset{shade, left color=#1, right color=#2, shading=diagonalfill}
    }
}

\tikzstyle{node-base}=[circle, draw, align=center, font=\footnotesize, minimum size=1.3cm]
\tikzstyle{dc-node}=[node-base, shading angle=45, double color fill={AntiqueWhite}{LightBlue}]

\begin{document}
\begin{tikzpicture}
  \node[dc-node] (n1) at (0, 0) {N$_1$};
  \node[dc-node] (n2) at (2.5, -.5) {N$_2$};
\end{tikzpicture}
\end{document}

我原本期望分裂时倾斜 45 度,但显然我没有得到这个结果。我是不是错过了什么?

答案1

选项的顺序可能很重要。

在创建阴影后放置角度:

\tikzstyle{dc-node}=[node-base, double color fill={AntiqueWhite}{LightBlue},
shading angle=45
]

在此处输入图片描述

答案2

是的,选项的顺序很重要!您想通过node-like采取另一种方法吗pic?多个参数似乎使其更加灵活!

在此处输入图片描述

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
% #1 and #2 are colors; 
% #3 is node name, to refer later 
% (note: no space in node name)
% #4 is text of the node. It can be empty!
% #5 is rotating angle   
\tikzset{pics/rotating disk/.style args=
{#1/#2/#3/#4/#5}{code={%
\begin{scope}[pic actions,rotate=#5]
\fill[#1] (90:1) arc(90:270:1)--cycle;
\fill[#2] (90:1) arc(90:-90:1)--cycle;
\end{scope}
\path (0,0) node[pic actions,draw,circle,minimum size=2cm] (#3) {#4};
}}} 

% [scale=] should be with [transform shape]     
\path
(0,0)  pic{rotating disk=cyan/magenta/A/$A$/45}
(2,2)  pic[draw=red,scale=.5,transform shape]{rotating disk=violet/yellow/B//-20}
(3,-1) pic{rotating disk=green/orange/C/$C$/120}
(0,-3) pic{rotating disk=pink!50/cyan!50/N2/$N_2$/-45}
(-4,0) pic{rotating disk=pink!50/cyan!50/N1/$N_1$/-45};
\draw (A)--(B);
\draw[->] (A) -| (B);
\draw[stealth-] (C.30) .. controls +(-120:1) and +(45:2) .. (B); 
\end{tikzpicture}
\end{document}  

相关内容