我正在尝试使用 LatexDraw 绘制下图,但渲染时遇到了困难。获得有关如何使用 TikZ 生成下图的指示将非常有帮助。
下面是代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,shadows,arrows}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
\begin{document}
\begin{tikzpicture}
% Method 2 overlapping nodes
\node[rotate=90, fill=gray!20,
minimum height=2em, text width=6em,rounded corners, drop shadow] at (3,1.5) { \hspace{0.5em}Input Layer};
\node[rotate=90, fill=red!20,
minimum height=2em, text width=8em,rounded corners, drop shadow] at (5,1.5) { \hspace{1em}Shared Layer};
\node[draw, minimum size=0.5cm, fill=blue!20] at (7,0.5) {};
\node[draw, minimum size=0.5cm, fill=green!20] at (7,1.5) {};
\node[draw, minimum size=0.5cm, fill=yellow!20] at (7,2.5) {};
\node[text width=8em] at (7.5,3.5) {Task Specific \\ \hspace{0.6em} Layer};
\node(n1)[draw, minimum size=0.5cm, fill=blue!20] at (9,0.5) {} ;
\node(n2)[draw, minimum size=0.5cm, fill=green!20] at (9,1.5) {} ;
\node(n3)[draw, minimum size=0.5cm, fill=yellow!20] at (9,2.5) {} ;
\node[text width=8em] at (10,3.5) {Output \\ \hspace{0.1em} Layer};
\node (1) [right = of n1] {Task 3};
\draw [->] (n1) -- (1);
\node (1) [right = of n2] {Task 2};
\draw [->] (n2) -- (1);
\node (1) [right = of n3] {Task 1};
\draw [->] (n3) -- (1);
\end{tikzpicture}
\end{document}
输出为
如何添加虚线交叉线?
答案1
作为起点:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
positioning,
shadows}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
\begin{document}
\begin{tikzpicture}[
node distance = 5mm and 11mm,
R/.style = {fill=#1, rounded corners,
minimum height=2em, inner xsep=2em,
rotate=90, anchor=center,
drop shadow},
N/.style = {draw, fill=#1, minimum size=2em}
]
%
\node (r1) [R=gray] {Input Layer};
\node (r2) [right=22mm of r1.south,R=red!20] {Shared Layer};
%
\node (n12) [N=green!30, right=of r2.south] {};
\node (n11) [N=blue!30, above=of n12] {};
\node (n13) [N=yellow!20, below=of n12] {};
%
\node (n21) [N=blue!30, right=of n11] {};
\node (n22) [N=green!30, right=of n12] {};
\node (n23) [N=yellow!20, right=of n13] {};
%
\draw [->] (n21) -- ++ (1.1,0) node[right] {Task 2};
\draw [->] (n22) -- ++ (1.1,0) node[right] {Task 2};
\draw [->] (n23) -- ++ (1.1,0) node[right] {Task 2};
%
\node [align=center, above=of n11] {Task Specific \\ Layer};
\node [align=center, above=of n21] {Output \\ Layer};
% dashed lines
\draw[dashed, gray]
(r1.south east) -- (r2.north east)
(r1.south west) -- (r2.north west)
([shift={(1ex,-1ex)}] r1.south east) -- ([shift={(-.5ex,+1ex)}] r2.north west)
([shift={(1ex,+1ex)}] r1.south west) -- ([shift={(-.5ex,-1ex)}] r2.north east)
([shift={(1ex,-3ex)}] r1.south) -- ([shift={(-.5ex,+3ex)}] r2.north)
([shift={(1ex,+3ex)}] r1.south) -- ([shift={(-.5ex,-3ex)}] r2.north)
%
;
\end{tikzpicture}
\end{document}