我正在尝试为我的项目制作一个 tikz 图形。我能够通过在线帮助开始并理解概念。虽然我无法制作完整的图形,但有人能帮我吗?
可以从 .png 文件导入猫和声波的图像。<cat.png 和 sound.png>
我已经在 draw.io 工具中制作了这个图形,可以通过以下方式访问:关联
我的尝试:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta, shapes.geometric, decorations.pathreplacing, calligraphy}
\begin{document}
\begin{tikzpicture}[
>=Stealth,
encoder/.style={
draw,
fill=gray!20,
trapezium,
trapezium left angle=70,
trapezium right angle=70,
minimum height=2cm,
minimum width=1cm,
text width=2.5cm,
align=center,
inner xsep=0pt
},
label/.style={
align=left
},
vector/.style={
draw,
minimum height=1cm,
minimum width=1cm,
fill=#1,
text centered
}
]
% Text Encoder block
\node[encoder] (encoder) at (10,0) {Text Encoder};
% Labels for sound descriptions
\node[label] (label1) at (0,1) {1 : The sound of dog};
\node[label] (label2) at (0,0) {2 : The sound of cat};
\node[label] (label3) at (0,-1) {3 : The sound of rain};
\node[label] (label4) at (0,-2) {4 : The sound of thunder};
% Lines from labels to Text Encoder
\draw[->] (label1.east) -- (label1-|encoder.west);
\draw[->] (label2.east) -- (label2-|encoder.west);
\draw[->] (label3.east) -- (label3-|encoder.west);
\draw[->] (label4.east) -- (label4-|encoder.west);
% Colored vectors (T1 to T4)
\node[vector=blue!30] (T1) at ([shift={(1cm,0.5cm)}]encoder.east) {T1};
\node[vector=green!30, below=0 of T1] (T2) {T2};
\node[vector=yellow!30, below=0 of T2] (T3) {T3};
\node[vector=orange!30, below=0 of T3] (T4) {T4};
% Arrow from Text Encoder to T1-T4
\draw[->] (encoder.east) -- (T1.west |- encoder.east);
\draw[->] (encoder.east) -- (T2.west |- encoder.east);
\draw[->] (encoder.east) -- (T3.west |- encoder.east);
\draw[->] (encoder.east) -- (T4.west |- encoder.east);
\end{tikzpicture}
\end{document}
答案1
真的,我只是想做猫,而 OP 根本不想要。但我也做了 OP 需要帮助的部分,所以猫似乎还算公平。
结果取决于 Ti钾Z 库在编译时可用。因此,您可能会得到一只条纹橘子猫……
...或者你可能会得到一只幸运的黑猫...
\documentclass[tikz,border=10pt]{standalone}
% ateb: https://tex.stackexchange.com/a/703854/ addaswyd o gwestiwn Formal_that: https://tex.stackexchange.com/q/703831/
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta, shapes.geometric,shapes.multipart,matrix,calc,ext.paths.ortho}
\newif\ifcathod
\cathodfalse
\IfFileExists{tikzlibrarycathod.code.tex}{\usetikzlibrary{cathod}\cathodtrue}{\usetikzlibrary{tikzlings}}
\newdimen\tempdima
\newdimen\tempdimb
\newdimen\tempdimc
\newlength\templengtha
\begin{document}
\begin{tikzpicture}[
>=Stealth,
every node/.style={font=\sffamily},
encoder/.style={
draw,
fill=gray!20,
trapezium,
trapezium left angle=70,
trapezium right angle=70,
align=center,
inner xsep=0pt,
rotate=-90,
},
label/.style={
align=left
},
vector/.style={
draw,
minimum height=1cm,
minimum width=1cm,
fill=#1,
text centered
},
AT/.style={inner ysep=20pt,draw=black},
]
\matrix (snds) [matrix of nodes,every node/.append style={anchor=base west}]
{
1 & : & The sound of a dog\\
2 & : & The sound of a cat\\
3 & : & The sound of rain\\
4 & : & The sound of thunder\\
};
% Text Encoder block
\node [encoder,right=of snds.east,anchor=south] (encoder) {Text\\Encoder};
% Colored vectors (T1 to T4)
\node (T) [rectangle split,rectangle split horizontal,AT,below right=20pt and 60pt of encoder.north east,anchor=north west,rectangle split part fill={blue!30,green!30,yellow!30,orange!30},rectangle split part align={base}] { T1 \nodepart{two} T2 \nodepart{three} T3 \nodepart{four} T4};
\node [encoder,below=20pt of encoder |- T.south,anchor=west] (enc) {Audio\\Encoder};
\node (a1) [AT,fill=red!30,anchor=west] at (enc.center -| {$(enc.north)!.5!(T.west)$}) {A1};
\path (T.west);
\pgfgetlastxy{\tempdima}{\tempdimb}
\path (T.east);
\pgfgetlastxy{\tempdimb}{\tempdimc}
\pgfmathsetlength \templengtha{(((\tempdimb-\tempdima)/4)-height("X")-0.8pt)/2}
\node (a) [inner ysep=\templengtha,rectangle split,rectangle split part fill={gray!30,gray!30,blue!50!gray!30,gray!30},rotate=-90,draw=black] at (T.center |- enc.center) { AAAA \nodepart{two} AAAA \nodepart{three} AAAA \nodepart{four} AAAA};
\ifcathod \path ([yshift=20pt]snds-3-3.east |- enc.west) pic {cath eistedd={enw=cat,maint=1mm,stripiau=orange!50!brown,llenwi=orange!50!brown!50!white,lliw=brown}} ;
\else \path ([yshift=20pt]snds-3-3.east |- enc.south) pic [scale=.5] {cat};
\fi
% Arrow from Text Encoder to T1-T4
\draw[->] (encoder.north) -| (T.north);
\foreach \i in {north east,south east}\draw [->,rounded corners] (snds.\i) -|- (encoder.south);
\draw (enc.north) [->] -- (a1.west);
\end{tikzpicture}
\end{document}