我正在努力画一TikZ
幅画。这就是我想要画的(忽略划掉的箭头)。
到目前为止我的图形如下所示:
这是我拥有的代码,所以本质上我正在努力解决水平箭头问题。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,thin,black}]
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\node[rectangle,
draw = black,
minimum width = 2cm,
minimum height = 3cm, anchor = west] (t) at (0,0) {DNN};
\node[rectangle,
draw = black,
minimum width = 3cm,
minimum height = 1cm, anchor = west, rotate = -90] (g) at (3.5,1.5) {argmax};
\node[rectangle,
draw = black, left = of t,
minimum width = 1cm,
minimum height = 0.4cm, yshift = 1.3cm, anchor = east] (u) {Emb};
\node[rectangle,
draw = black, left = of t,
minimum width = 1cm,
minimum height = 0.4cm, yshift = 0.3cm, anchor = east] (v) {Emb};
\node[rectangle,
draw = black, left = of t,
minimum width = 1cm,
minimum height = 0.4cm, yshift = 0.-1.3cm, anchor = east] (v) {Emb};
\node[rectangle,
draw = black, left = of t,
minimum width = 1cm,
minimum height = 0.4cm, yshift = -0.3cm, anchor = east] (v) {Emb};
\node(dots) at (-1.5,-0.7){\vdots};
\node(dots) at (-1.5,0.9){\vdots};
\end{tikzpicture}
\end{document}
答案1
与 Miyase 发布的内容没有太大区别,但定位工具和命令不同
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,thin,black}]
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\node[rectangle,
draw = black,
minimum width = 2cm,
minimum height = 3cm, anchor = west] (t) at (0,0) {DNN};
\node[rectangle,
draw = black,
minimum width = 3cm,
minimum height = 1cm, anchor = west, rotate = -90] (g) at (3.5,1.5) {argmax};
\node[rectangle,
draw = black, left = of t.north west, anchor=north east,
minimum width = 1cm,
minimum height = 0.4cm] (emb1) {Emb};
\node[rectangle,
draw = black, below = 4mm of emb1,
minimum width = 1cm,
minimum height = 0.4cm] (emb2) {Emb};
\node[rectangle,
draw = black, left = of t.south west, anchor=south east,
minimum width = 1cm,
minimum height = 0.4cm, fill=blue!50] (emb4) {Emb};
\node[rectangle,
draw = black, above = 4mm of emb4,
minimum width = 1cm,
minimum height = 0.4cm, fill=blue!50] (emb3) {Emb};
\path (emb1)--node[pos=0.25] {\vdots} (emb2);
\path (emb3)--node[pos=0.25] {\vdots} (emb4);
\foreach \i in {1,2,3,4}{
\draw[->] (emb\i)--(emb\i-|t.west);
\draw[->] (emb\i-|t.east)-- node[above]{Q\i}(emb\i-|g.south);
\draw[<-] (emb\i.west)--++(180:5mm) node[left]{SNR};
}
\draw[->] (g)--++(0:1cm);
\end{tikzpicture}
\end{document}
答案2
以下是一个基本的答案。希望您能够根据自己的喜好做出选择。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,calc}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,thin,black}]
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\node [rectangle,
draw = black,
minimum width = 2cm,
minimum height = 3cm, anchor = west] (t) at (0,0) {DNN};
\node[rectangle,
draw = black,
minimum width = 3cm,
minimum height = 1cm, anchor = west, rotate = -90] (g) at (4,1.5) {argmax};
\node (Q1) at (3.6,1.2)[left]{$Q_1$};
\node (Q2) at (3.6,0.4)[left]{$Q_2$};
\node (Q3) at (3.6,-0.4)[left]{$Q_3$};
\node (Q4) at (3.6,-1.2)[left]{$Q_4$};
\draw[->, >=latex] (Q1-|t.east)--(Q1.west);
\draw[->, >=latex] (Q2-|t.east)--(Q2.west);
\draw[->, >=latex] (Q3-|t.east)--(Q3.west);
\draw[->, >=latex] (Q4-|t.east)--(Q4.west);
\draw[->, >=latex] (g.north)--++(1,0);
\node[rectangle,
draw = black, left = of t,
minimum width = 1cm,
minimum height = 0.4cm, yshift = 1.3cm, anchor = east] (u) {Emb};
\draw[->, >=latex] (u.east)--(u-|t.west);
\node[rectangle,
draw = black, left = of t,
minimum width = 1cm,
minimum height = 0.4cm, yshift = 0.3cm, anchor = east] (v) {Emb};
\draw[->, >=latex] (v.east)--(v-|t.west);
\node[rectangle,
draw = black, left = of t,
minimum width = 1cm,
minimum height = 0.4cm, yshift = 0.-1.3cm, anchor = east] (w) {Emb};
\draw[->, >=latex] (w.east)--(w-|t.west);
\node[rectangle,
draw = black, left = of t,
minimum width = 1cm,
minimum height = 0.4cm, yshift = -0.3cm, anchor = east] (x) {Emb};
\draw[->, >=latex] (x.east)--(x-|t.west);
\draw[dotted] (u.south)--(v.north);
\draw[dotted] (x.south)--(w.north);
\draw[->, >=latex] ($(u.west)-(1,0)$) node[left]{SNR}--(u.west);
\draw[->, >=latex] ($(v.west)-(1,0)$) node[left]{SNR}--(v.west);
\draw[->, >=latex] ($(w.west)-(1,0)$) node[left]{SNR}--(w.west);
\draw[->, >=latex] ($(x.west)-(1,0)$) node[left]{SNR}--(x.west);
\end{tikzpicture}
\end{document}
答案3
绘制此方案的另一种变体。使用的是arrows.meta
、fit
和positioning
库,“Emb”节点相对于彼此定位,“DNN”和“argmax”使用fit
坐标表示左上角和右下角节点。对于节点,定义了两种样式:emb
和FIT
:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
fit,
positioning}
\begin{document}
\begin{tikzpicture}[
> = Straight Barb,
node distance = 4mm and 12mm,
emb/.style = {draw, fill=#1, minimum width=10mm, minimum height=4mm,
node contents={Emb}},
emb/.default = none,
FIT/.style = {draw, fit=#1, inner sep=0pt},
]
\node (n1) [emb];
\node (n2) [emb, below=of n1];
\node (n3) [emb=blue!50, below=of n2];
\node (n4) [emb=blue!50, below=of n3];
\path (n1)--node[pos=0.25] {\vdots} (n2)
(n3)--node[pos=0.25] {\vdots} (n4);
%
\coordinate[right=of n1.north east] (dnn1);
\coordinate[right=of n4.south -| dnn1] (dnn2);
\node (n5) [FIT=(dnn1) (dnn2), label=center:DNN] {};
%
\coordinate[right=of n5.north east] (am1);
\coordinate[right=of n5.south -| am1] (am2);
\node (n6) [FIT=(am1) (am2), label={[rotate=-90]center:argmax}] {};
%%
\foreach \i in {1,2,3,4}%
{
\draw[->] (n\i) -- (n\i -| n5.west);
\draw[->] (n\i -| n5.east)-- node[above] {Q\i} (n\i -| n6.west);
\draw[<-] (n\i.west) --++ (-0.5,0) node[left] {SNR};
}
\draw[->] (n6) --++ (1,0);
\end{tikzpicture}
\end{document}