在 tikz 中为图片指定一个名称

在 tikz 中为图片指定一个名称

我在 tikz 中有一个 /.pic,但我无法为其指定名称。我想在该图片的右侧绘制一些块。我已附上我想要的图形。你能帮我解决这个问题吗?谢谢。这是我想要的图形https://i.stack.imgur.com/aw7Xh.jpg

\usetikzlibrary{positioning,arrows.meta,calc}
\begin{document}
\tikzset
{myTrapezium/.pic ={\draw [fill=magenta!50] (0,0) -- (0,\b) -- (\a,\c) -- (\a,-\c) -- (0,-\b) -- cycle ;
\coordinate (-center) at (\a/2,0);
\coordinate (-out) at (\a,0);},
block/.style={draw, fill=blue!15, rectangle, minimum height=2em, minimum width=2.1em, font = \Large},
dot/.style = {circle,fill, inner sep=0.01mm, fill=black!15, node contents={}},
  myArrows/.style={line width=2mm, red,-{Triangle[length=1.5mm,width=5mm]},shorten >=2pt, shorten <=2pt, }}

    \def\a{2}  % width of trapezium
    \def\b{.9} % small height of trapezium
    \def\c{2}  % tall height of trapezium

\begin{tikzpicture}
[node distance=1mm, % space between drawn parts
every node/.style={align=center},]
 \coordinate (start) at (-4.08,4.5);
 \node[block, below = 8cm of start] (Alpha) {$x$};
 \node[block, below = 2cm of Alpha] (zed) {$y$};
  \pic (left)[right=3cm of Alpha, rotate=180] {myTrapezium} ;
\node at (left-center) {a} ;
  \def\d{.9}
  \coordinate (u) at (\d,0);
\end{tikzpicture}
\end{document}```

答案1

为什么不使用已经提供的trapezium形状?

\documentclass[tikz, border=2mm]{standalone}

\usetikzlibrary{positioning, arrows.meta, calc, shapes.geometric}
\begin{document}
\begin{tikzpicture}
    \node[trapezium, draw, minimum height=2cm, fill=magenta!50, shape border rotate=270] (a) {a};
    \draw ($(a.top left corner)!.2!(a.top right corner)$)--++(0:1cm) node[right, draw] {1};
    \draw ($(a.top left corner)!.8!(a.top right corner)$)--++(0:1cm) node[right, draw] {2};
    \draw ($(a.bottom left corner)!.2!(a.bottom right corner)$)--++(180:1cm) node[left, draw] {3};
    \draw ($(a.bottom left corner)!.8!(a.bottom right corner)$)--++(180:1cm) node[left, draw] {4};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容