答案1
本网站有很多类似的图表。为了找到可以借鉴的候选图表,你可以做一个视觉搜索。无论如何,这是绘制此图的众多方法之一。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}[>=latex,box/.style={draw,inner sep=1ex,thin},semithick]
\matrix[matrix of nodes,nodes={box},row sep=1em](mat) {
|[label={[name=l2]below:{$x(A_2)$}}]|Decoder 1\\
|[label={[align=center,yshift=1ex,name=l3]below:{$\vdots$\\ $x(A_n)$}}]|Decoder 2\\
Decoder $n$\\
};
\node[above=1em of mat-1-1] (l1) {$x(A_1)$};
\node[left=3em of mat.west,box] (E){Encoder};
\draw (E.east) -- ++ (2em,0) coordinate (aux) node[midway,above]{$y$};
\draw[<-] (E.west) -- ++ (-6em,0) node[midway,above]{$x_1,\dots,x_n$};
\foreach \X in {1,2,3} {
\draw[->] (l\X) -- (mat-\X-1);
\draw[->] (mat-\X-1.east) -- ++ (2.5em,0) node[midway,above]{$x_{\X}$};
\draw[->] (aux) |- (mat-\X-1);
}
\end{tikzpicture}
\end{document}
我认为公平地说,使用quotes
和chains
不会使代码更优雅。
答案2
作为薛定谔的巧妙解决方案的替代,我想为讨论贡献一种基于森林的方法:
\documentclass[]{article}
\usepackage{forest}
\useforestlibrary{edges}
\usetikzlibrary{arrows.meta, math}
\tikzmath{
\Len{l sep} = 2.1cm;
\Len{fork sep} = \Len{l sep}/2;
\Len{s sep} = 1cm;
\Len{label sep} = 0.3cm;
}
\newcommand\Label[1]{%
\draw [<-, >=Latex] (.north) to ++(0,\Len{label sep} pt) node[above, inner ysep=1pt]{$#1$};
}
\newcommand\EdgeLabelNode[1]{%
node[midway, above]{$#1$}
}
\forestset{
e-label/.style = {
edge label={\EdgeLabelNode{#1}}
}
}
\begin{document}
\begin{forest}
for tree = {
grow'=east,
l sep=\Len{l sep},
s sep=\Len{s sep},
fork sep=\Len{fork sep},
anchor=west,
parent anchor=east,
child anchor=west,
forked edge',
edge={->, semithick, >=Latex}
},
for nodewalk={
*{2}{children}
}{
node options={draw, semithick, inner ysep=1em, inner xsep=2em}
}
[,
[Encoder, for n=3{s=-2.6*\Len{s sep}}, e-label={x_1,\ldots, x_n}
[Decoder 1,
[,e-label={x_1}]
]{\Label{x\left(A_1\right)}}
[Decoder 2,
[,e-label={x_2}]
]{\Label{x\left(A_2\right)}}
[Decoder 3
[,e-label={x_n}]
]{
\Label{x\left(A_n\right)}
\draw[loosely dotted, thick] ($(.north)!0.6!(!p.south)$) -- ($(.north)!0.9!(!p.south)$);
}
] { \path(.east) -- ++(\Len{fork sep} pt,0) \EdgeLabelNode{y};}
]
\end{forest}
\end{document}
笔记
如果有人知道一个更优雅的解决方案来标记“编码器”和“解码器...”之间的路径,我将不胜感激。