答案1
我告诉你,这不是开始使用 tikz 的最佳绘图。它有很多元素需要绘制:线条、圆圈、箭头……话虽如此,我认为这里有两个关键:定位必要的坐标和使用命令\foreach
。
首先,我将为您提供一张带有我定义的坐标的“地图”,因此我避免解释每个坐标在哪里。
现在,来看看代码。如果我把更多的东西放在同一个 中,代码可能会更少\foreach
。但我认为,将坐标、线条、标签等分开,我们的可读性会提高一点。好吧,我希望如此。我还使用arrows.meta
和decorations.markings
库将箭头放在线条中间。
如下。
\documentclass [border=2mm]{standalone}
\usepackage {tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\definecolor {myblue}{HTML}{3CADEF}
\tikzset {myposition/.store in=\myposition,myposition=0.5}
\begin{document}
\begin{tikzpicture}
[%
scale=0.8,thick,line cap=round,line join=round,%
myarrow/.style=%
{%
decoration={markings,mark=at position \myposition with {\arrow{Stealth}}},
postaction={decorate}
}
]
% Coordinates
\foreach\j in {1,2,3}
{%
\foreach[count=\xi]\i in {0,8}
{%
\coordinate (A\xi\j) at (\i+\j,0);
\coordinate (B\xi\j) at (\i+\j,8-2*\j);
\coordinate (C\xi\j) at (\i+\j,8);
\coordinate (D\xi\j) at (\i+\j,16-2*\j);
}
\coordinate (E\j) at (5, 8-2*\j);
\coordinate (F\j) at (7, 8-2*\j);
\coordinate (G\j) at (13, 8-2*\j);
\coordinate (H\j) at (-3,16-2*\j);
\coordinate (I\j) at (0,16-2*\j);
\coordinate (J\j) at (5,16-2*\j);
\coordinate (K\j) at (8,16-2*\j);
\coordinate (L\j) at (13,16-2*\j);
\coordinate (M\j) at (15,16-2*\j);
\coordinate (N\j) at (17,16-2*\j);
}
\coordinate (H0) at (-3,16);
\coordinate (J0) at ( 5,16);
% Blue lines
\foreach\j in {1,2,3}
{%
\foreach\i in {1,2}
{%
\draw[myblue,myarrow,myposition=0.4] (D\i\j) -- (C\i\j);
\draw[myblue,myarrow,myposition=0.6] (C\i\j) -- (B\i\j);
\draw[myblue,myarrow,myposition=0.6] (B\i\j) -- (A\i\j);
}
\draw[myblue,myarrow,myposition=0.3] (G\j) -- (B2\j);
\draw[myblue,myarrow,myposition=0.6] (B2\j) -- (F\j);
\draw[myblue] (E\j) -- (B1\j);
\foreach\k in {1,2,3}
{%
\draw[myblue,myarrow,myposition=0.3] (F\j) -- (E\k);
}
}
% Black lines
\foreach\j in {1,2,3}
{%
\draw[myarrow,myposition=0.8] (I\j) -- (D1\j);
\draw[myarrow] (D1\j) -- (J\j);
\draw[myarrow ] (K\j) -- (D2\j);
\draw[myarrow,myposition=0.6] (D2\j) -- (L\j);
\draw[myarrow,myposition=0.6] (L\j) -- (M\j);
\draw[myarrow,myposition=0.6] (N\j) -- (M\j);
\draw[myarrow,myposition=1] (M\j) --++ (0,-0.5);
\foreach\i in {0,...,3} \foreach\k/\l in {H/I,J/K}
{%
\draw[myarrow,myposition=0.3] (\k\i) -- (\l\j);
}
}
% Circles
\def\r{0.1} % radius
\foreach\j in {1,2,3}
{%
\foreach\i in {A1,B1,C1,D1,A2,B2,C2,D2,E,F,G}
{%
\draw[myblue,fill=white] (\i\j) circle (\r);
}
\foreach\i in {H,...,N}
{%
\draw[fill=white] (\i\j) circle (\r);
}
}
\draw[fill=white] (H0) circle (\r);
\draw[fill=white] (J0) circle (\r);
% Labels
\foreach\j in {1,2,3}
{
\node at (N\j) [above] {$d_\j$};
\node at (M\j) [yshift=-0.6cm] {$e_\j$};
\node at (L\j) [above right] {$o_\j-1$};
\node at ($(D2\j)!0.6!(L\j)$) [above] {$\varphi(\cdot)$};
\node at (J\j) [above] {$y_\j^{(1)}$};
\node at ($(D1\j)!0.5!(J\j)$) [above] {$\varphi(\cdot)$};
\node at (H\j) [left] {$x_\j$};
\node[myblue] at (G\j) [right] {$e_\j$};
\foreach\i in {1,2}
{%
\node[myblue] at (D\i\j) [above] {$v_\j^{(\i)}$};
\node[myblue,fill=white,inner sep=1pt] at (C\i\j) [yshift=0.4cm] {$v_\j^{(\i)}$};
\node[myblue] at ($(B\i\j)!0.4!(C\i\j)$) [right] {$\varphi(\cdot)$};
\node[myblue] at (A\i\j) [below] {$\delta_\j^{(\i)}$};
}
\foreach[count=\xi]\i in {H,J}
{%
\node at (\i0) [above] {$+1$};
\node at (\i0) [xshift=1.2cm] {$w_{10}^{(\xi)}=b^{(\xi)}$};
\node at (\i3) [below,xshift=1cm] {$w_{13}^{(\xi)}$};
}
}
\node[myblue] at ($(E3)!0.5!(F3)$) [below] {$w_{31}^{(2)}$};
\end{tikzpicture}
\end{document}
答案2
欢迎来到 TeX.SX!以下是驯服这头野兽的一些想法:
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
dot/.style={
circle, draw, inner sep=1.5pt
},
arrow/.style={
decoration={markings,
mark=at position 0.5 with {\arrow{latex}}},
postaction={decorate}
}
]
\node[dot, label={90:$\upsilon_1^{(1)}$}] (u11) at (0,0) {};
\node[dot, label={300:$\varphi^\prime(\cdot)$}] (p1) at (0,-2) {};
\node[dot] (x1) at (2,-2) {};
\node[dot, label={270:$\delta_1^{(1)}$}] (d11) at (0,-5) {};
\draw[arrow] (u11) -- node[pos=.5, label={180:$\varphi^\prime(\cdot)$}] {} (p1);
\draw (p1) -- (x1);
\draw[arrow] (p1) -- (d11);
\end{tikzpicture}
\end{document}
您可以随时查阅非常全面和易懂的钛钾Z 手册获得基本帮助。