绘制粗线的问题

绘制粗线的问题

解决方案已发布这里,我只改了一点(在第17行,我添加了[thick, ->]之后\draw):

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}
[   cnode/.style={draw=black,fill=#1,minimum width=3mm,circle},
]
    \node[cnode=red,label=0:$\Sigma$] (s) at (6,-3) {};
    \node at (0,-4) {$\vdots$};
    \node at (3,-4) {$\vdots$};
    \foreach \x in {1,...,4}
    {   \pgfmathparse{\x<4 ? \x : "n"}
        \node[cnode=blue,label=180:$x_{\pgfmathresult}$] (x-\x) at (0,{-\x-div(\x,4)}) {};
        \node[cnode=gray,label=90:$\varphi_{\pgfmathresult}$] (p-\x) at (3,{-\x-div(\x,4)}) {};

        %%%%%%%%Changed this line   
        \draw[thick, ->] (p-\x) -- node[above,sloped,pos=0.3] {$\omega_{\pgfmathresult}$} (s);
    }
    \foreach \x in {1,...,4}
    {   \foreach \y in {1,...,4}
        {   \draw (x-\x) -- (p-\y);
        }
    }
\end{tikzpicture}

\end{document}

输出如下:

请注意,文本\omega已更改为0.8。为什么会发生这种情况以及如何解决?

答案1

想象\pgfmathresult一下\temp,每次进行数学运算时,它都会被覆盖。thick使线宽为 0.8pt,并在某个地方用作数学运算。所以,\pgfmathresult被覆盖了。相反,如果你把它变成一个固定的宏来保存值,它就会按预期工作

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}
[   cnode/.style={draw=black,fill=#1,minimum width=3mm,circle},
]
    \node[cnode=red,label=0:$\Sigma$] (s) at (6,-3) {};
    \node at (0,-4) {$\vdots$};
    \node at (3,-4) {$\vdots$};
    \foreach \x in {1,...,4}
    {   \pgfmathsetmacro\mytemp{\x<4 ? int(\x) : "n"}
        \node[cnode=blue,label=180:$x_{\mytemp}$] (x-\x) at (0,{-\x-div(\x,4)}) {};
        \node[cnode=gray,label=90:$\varphi_{\mytemp}$] (p-\x) at (3,{-\x-div(\x,4)}) {};
        \draw[thick, ->] (p-\x) -- node[above,sloped,pos=0.3] {$\omega_{\mytemp}$} (s);
    }
    \foreach \x in {1,...,4}
    {   \foreach \y in {1,...,4}
        {   \draw (x-\x) -- (p-\y);
        }
    }
\end{tikzpicture}

\end{document}

相关内容