我将请您解决一个稍微复杂一点的问题。也许它并不像看起来那么难,但对我来说,它很难。假设我想为这些绘图创建四个自己的宏\objecta
,,,\objectb
:\objectc
\objectd
\documentclass{article}
\usepackage{tikz}
\newcommand{\objecta}[1]{
\begin{tikzpicture}\draw (0,0)--(1,0)--(1,1)--(0,1)--cycle;
\draw [->](-0.2,0.5)--(0.5,1.2);
\node at (-0.5,0.5){#1};
\end{tikzpicture}}
\newcommand{\objectb}[2]{
\begin{tikzpicture}
\draw (0,0)--(2,0)--(2,1)--(0,1)--cycle;
\draw (0.3,0.5)--(0.5,0.5);
\draw (1.5,0.5)--(1.7,0.5);
\draw (0.5,0.35)--(1.5,0.35)--(1.5,0.65)--(0.5,0.65)--cycle;
\node at (0.2,0.8){$\triangledown$};
\node at (1.8,0.2){$T$};
\node at (0.4,1.2){#1};
\node at (-0.3,0.5){#2};
\end{tikzpicture}}
\newcommand{\objectc}{
\begin{tikzpicture}
\node[minimum height=2cm,minimum width=2cm, draw, rectangle] at (0,0) {PI};
\draw (0.3,-1)--(1,0)--(0.3,1);
\end{tikzpicture}}
\def\objectd{\node [circle,draw] {M};}
\begin{document}
.
.
.
\end{document}
ObjectA 只有一个节点(标签)。ObjectB 有四个节点(标签)(首先绘制所有标签),但只有一个是默认节点(T)。其余两个对象都有默认节点。所以我的第一个问题是如何指定宏,当我没有输入任何内容时{#1} {#2} {#3} ...
将显示默认文本。
所以我有这些宏,现在我想像这样将它们连接在一起:
是否可以创建一个宏或程序来定位这些对象以及创建路径的宏/程序?我将仅指定第一个宏的节点、第二个宏的节点和将要创建的路径。
非常感谢。(如果语法不好请见谅)
编辑:
- 抱歉,我还是个新手,所以现在不知道我可以将什么定义为节点、锚点、标签,而我脑海中只有这些,而您可以有不同的解决方案。由于我没有发布任何代码,因为尽管这样对您来说,使用自己的代码比使用我笨拙的代码更容易。
- 节点默认文本的问题不大,我主要想获得有关定位和创建从宏到另一个宏的路径的帮助。如果可能的话,如何为其创建宏或程序。
- 添加了宏代码,如您所见,这是笨拙的代码。不知道如何处理节点放置(文本)才好。
- 嗯,我的帖子又需要编辑了——因为有图片
- 如能得到任何帮助我将不胜感激,因为我已经完全迷失了方向,不知道该怎么办。
- 如果可以的话我愿意提供更多帮助,但不知道该怎么做
答案1
回答未回答的问题……
在聊天会话中,我们定义了其中两种节点形状,如下所示,其他节点形状则向社区提出要求在这个问题中。
\documentclass{article}
\usepackage{tikz}
\makeatletter
\pgfdeclareshape{pinode}{
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\backgroundpath{%
\pgfpathrectanglecorners{\southwest}{\northeast}
\northeast \pgf@xa=0\pgf@x \pgf@ya=\pgf@y \pgf@xb=\pgf@x
\southwest \pgf@yc = \pgf@y \pgf@yb=0pt
\advance \pgf@xa by .9\wd\pgfnodeparttextbox
\advance \pgf@yb by .5\ht\pgfnodeparttextbox
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yc}}
\pgfusepath{stroke}
}
}
\pgfdeclareshape{arrowednode}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\backgroundpath{%
\pgfpathrectanglecorners{\southwest}{\northeast}
\pgfusepath{stroke}
\northeast \pgf@ya=\pgf@y
\southwest \pgf@xa= \pgf@x
\pgfsetarrowsstart{stealth}
\pgfpathmoveto{\pgfpointadd{\pgfpoint{\pgf@xa}{\pgf@ya}}{\pgfpoint{6mm}{3mm}}}
\pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xa}{\pgf@ya}}{\pgfpoint{-3mm}{-6mm}}}
\pgfusepath{stroke}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw[opacity=0.2,style=help lines] (-1,-1) grid[step=1cm] (6cm,6cm);
\node [draw,arrowednode,inner sep=5mm] (a) at (0,4) {Y};
\node [draw,pinode,inner sep=5mm] (b) at (4,5) {PI};
\node [draw,arrowednode,inner sep=0.5cm] (c) at (0,2) {X};
\node [draw,pinode,inner sep=0.5cm] (d) at (0,0) {Z};
\draw[->,thick] (d.east)-| ++(1.5,0) |- (b.205);
\draw[->,thick] (c.east)-| ++(1,0) |- (b.180);
\draw[->,thick] (a.east)-| ++ (0.5cm,1cm) |- (b.155);
\end{tikzpicture}
\end{document}