如何制作大小相同的循环 tikzpicture (Tikz101)

如何制作大小相同的循环 tikzpicture (Tikz101)

以下是我的代码和相应的投影仪幻灯片:

'\documentclass{beamer}
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{textcomp}
\usetikzlibrary{arrows, positioning, shapes.geometric}

\begin{document}
% Definition of blocks:

%------------------------------------------------
\tikzstyle{block} = [rectangle, minimum width=1.5cm, minimum height=1cm, text centered, text width=1.5cm, draw=black, fill=white]
\tikzstyle{dormant.block} = [rectangle, minimum width=1.5cm, minimum height=1cm, text centered, text width=1.5cm, draw=black, fill=gray!30]
\tikzstyle{text.block} = [rectangle, minimum width=0.5cm, minimum height=1cm, text centered, text width=0.5cm, draw=white, fill=white]
\tikzstyle{label.block} = [rectangle, minimum width=1.5cm, minimum height=1cm, text centered, text width=1.5cm, draw=white, fill=white]
\tikzstyle{s.block} = [rectangle, minimum width=0.5cm, minimum height=1cm, text centered, text width=0.5cm, draw=white, fill=white]

 %------------------------------------------------
 \tikzstyle{FIX} = [circle,minimum size=1em,text centered, draw=white]
 \tikzstyle{adder} = [circle,minimum size=1em,text centered, draw=black]

  %------------------------------------------------
  \tikzstyle{arrow} = [thick,->,>=stealth]
  \tikzstyle{rarrow} = [thick,<-,>=stealth]

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 \begin{frame}
 \frametitle{Dummy}
 \begin{center} 
 \begin{tikzpicture}[node distance=2 cm]
 \node(ref.pnt) at (-9.5,3.4) [FIX]{};
 \node(b1)  [text.block, right of=ref.pnt, xshift=-3.33cm]  {B1};
 \node(b2)  [block, right of=b1, xshift=-0.0cm]             {B2};
 \node(b3)  [s.block, right of=b2, xshift=0.3cm]            {*};
 \node(b4)  [block, right of=b3, xshift=0.3cm]              {B4};
 \node(b5)  [block, right of=b4, xshift=0.8cm]              {B5};
 \node(b6)  [adder, below of=b5, yshift=0.5cm]              {+};
 \node(b7)  [text.block, right of=b6, xshift=-0.75cm]       {B7};
 \node(b8)  [block, below of=b6, yshift=0.5cm]              {B8};
 \node(b9)  [block, left of=b8, xshift=-0.8cm]              {B9};
 \node(b10) [s.block, left of=b9, xshift=-0.3cm]            {*};
 \node(b11) [s.block, below of=b10, xshift=-0.0cm]          {*};
 \node(b12) [block, left of=b10, xshift=-0.3cm]             {B12};
 \node(b13) [text.block, left of=b12, xshift=0.0cm]         {B13};

 \draw [arrow]  (b1)    --   (b2);
 \draw [arrow]  (b2)    --   (b3);
 \draw [arrow]  (b3)    --   (b4);
 \draw [arrow]  (b4)    --   (b5);
 \draw [arrow]  (b5)    --   (b6);
 \draw [arrow]  (b7)    --   (b6);
 \draw [arrow]  (b6)    --   (b8);
 \draw [arrow]  (b8)    --   (b9);
 \draw [arrow]  (b9)    --   (b10);
 \draw [arrow]  (b10)   --   (b12);
 \draw [arrow]  (b12)   |-   (b11);
 \draw [arrow]  (b12)   --   (b13);
 \draw [rarrow] (b9.south)++(-.3,0) |- (b11.east); 
 \draw [arrow]  (b9.south)++(.3,0) |- ++(0,-1.5) -| (b8);

 \node(type2)  [label.block, below of=b11, yshift=0.8cm] {$Type-II$};

 \end{tikzpicture}
 \end{center}
 \end{frame}

 \end{document}`

在此处输入图片描述

我想制作两个循环

  1. B8-B9-B8
  2. B9-$\lambda$-B12-$\gamma$-B9

大小相等。我该怎么做呢?我尝试使用“xshift”,但它会将整个图表向左和向右移动,而不是单个节点。其次,我想用更友好的东西替换 (-9.5,3.4) [FIX]{}; 处的 \node(ref.pnt)。我定义了 ref.pnt,以便我的所有块都相对于这个固定点绘制。

答案1

我不确定参考点的意义是什么,因为一切都是相对的。(不只是关于物理学的观点,而是 TikZ。)

有多种方法可以简化此操作:使用网格、使用不同的包、使用库。我非常喜欢chains这种方法,但这可能只是我的偏好。

您可以依靠自动编号来命名链,也可以指定节点名称。在这里,我根据最简单的方法混合使用。自动方法的缺点是插入节点会更改链中后面的名称。但我想任何自动命名都会有这样的问题。

请注意,它\tikzstyle已被弃用,该arrows库也已被弃用。

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{arrows.meta,positioning,chains,scopes}
\begin{document}
\tikzset{%
  block/.style = {rectangle, minimum width=1.5cm, minimum height=1cm, text centered, text width=1.5cm, draw=black, fill=white},
  s.block/.style = {rectangle, minimum width=0.5cm, minimum height=1cm, text centered, text width=0.5cm, draw=black, fill=white},
  text.block/.style = {rectangle, minimum width=0.5cm, minimum height=1cm, text centered, text width=0.5cm, draw=white, fill=white},
  label.block/.style = {rectangle, minimum width=1.5cm, minimum height=1cm, text centered, text width=1.5cm, draw=white, fill=white},
  adder/.style = {circle,minimum size=1em,text centered, draw=black},
  arrow/.style = {thick,->,>=Stealth},
  rarrow/.style = {thick,<-,>=Stealth},
}

\begin{tikzpicture}[node distance=2cm, start chain=b going right, every on chain/.append style={join}, every join/.append style=arrow]
  \node [on chain, text.block] {B1};
  \node [on chain, block] {B2};
  \node [on chain, s.block] {*};
  \node [on chain, block] {B4};
   {[every join/.style=thick]\node [on chain, coordinate] {};}
  \node [on chain, block] {B5};
  {[continue chain=b going below]
    \node [on chain, adder] {*};
    {[start branch=A going right, every join/.style=rarrow]
      \node [on chain, text.block] {B7};
    }
    \node [on chain, block] {B8};
  }
  {[continue chain=b going left]
    {[every join/.style=thick]\node [on chain, coordinate] {};}
    \node [on chain, block] {B9};
    \node (b10) [on chain, s.block] {*};
    \node (b12) [block, on chain] {B12};
    {[start branch=C going below, every join/.style=thick]
      \node [on chain, shape=coordinate] {};
    }
    \node [on chain, text.block] {B13};
  }
  {[continue chain=b/C going right]
    \node (b11) [s.block, label={[label.block]below:$Type-II$}] at (b10 |- b/C-2) {*};
    \chainin (b11);
  }
  \draw [arrow] (b11) -| ([xshift=-5pt]b-10.south);
  \draw [arrow] ([xshift=5pt]b-10.south) |- (b-9 |- b/C-2) -| (b-8.south);
\end{tikzpicture}
\end{document}

节点链

相关内容