tikz def 节点名称(或引用)用于使用 def 创建的节点

tikz def 节点名称(或引用)用于使用 def 创建的节点

为了创建圆柱形状的节点,我有以下定义

\def\dnc[#1,#2,#3,#4]#5{
  \node[draw, cylinder, alias=cyl, shape border rotate=90, aspect=1.6, %
  minimum height=25, minimum width=20, outer sep=-0.5\pgflinewidth, %
  color=orange!40!black, left color=orange!70, right color=orange!80, middle
  color=white] (#4) [below=of #1, xshift=#2] {};%
  \node  [below=of #1, xshift=#2, yshift=#3] {#5};%
  \fill [orange!30] let \p1 = ($(cyl.before top)!0.5!(cyl.after top)$), \p2 =
  (cyl.top), \p3 = (cyl.before top), \n1={veclen(\x3-\x1,\y3-\y1)},
  \n2={veclen(\x2-\x1,\y2-\y1)} in (\p1) ellipse (\n1 and \n2);
};

另一个 def 在方形节点中创建这些的集合。

\def \cnb[#1]#2{
  \node[computenode] (#1) {#2}; 
  \dnc[#1.west, 7mm, -3mm, a1]{$\A_1$};
  \dnc[#1.east, -7mm, -3mm, a1]{$\A_2$};
  \dnc[#1.north west, 7mm, -3mm, a1]{$\A_3$};
  \dnc[#1.north east, -7mm, -3mm, a1]{$\A_4$};
};

我的问题是,在创建边时,我无法通过名称引用节点(圆柱体)。我收到错误

不知道形状 a1。

答案1

我根据评论部分完善了代码,这是我努力的成果。

\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\pagecolor{white}
\tikzset{computenode/.style={red},
  a1/.style={blue},
  }% End of \tikzset...
\def\A{A}

\def\dnc[#1, #2, #3, #4]#5{%
  \node[draw, cylinder, alias=cyl, shape border rotate=90, aspect=1.6,%
  minimum height=25, minimum width=20, outer sep=-0.5\pgflinewidth,%
  color=orange!40!black, left color=orange!70, right color=orange!80, middle
  color=white] (#4) [below=of #1, xshift=#2] {};%
  \node[below=of #1, xshift=#2, yshift=#3] {#5};%
  \fill[orange!30] let
    \p1 = ($(cyl.before top)!0.5!(cyl.after top)$), 
    \p2 = (cyl.top), 
    \p3 = (cyl.before top), 
    \n1={veclen(\x3-\x1,\y3-\y1)},
    \n2={veclen(\x2-\x1,\y2-\y1)} 
     in (\p1) ellipse (\n1 and \n2);
  }% End of \dnc...

\def \cnb[#1]#2{
  \node[computenode] (#1) {#2}; 
  \dnc[#1.west, 7mm, -3mm, a1]{$\A_1$}
  \dnc[#1.east, -7mm, -3mm, a1]{$\A_2$}
  \dnc[#1.north west, 7mm, -3mm, a1]{$\A_3$}
  \dnc[#1.north east, -7mm, -3mm, a1]{$\A_4$}
  }% End of \cnb...

\begin{document}
\begin{tikzpicture}
\cnb[namefrom]{My cylinder!}
\end{tikzpicture}
\end{document}

最小当量,气缸

相关内容