Tikz 盒子尺寸调整

Tikz 盒子尺寸调整

我遇到了一个与盒子尺寸有关的问题。是否有可能将名为“较短”的盒子缩短到全尺寸的 2/3。此外,箭头的锚点应该位于中间。我希望你能理解这个问题。以下是玩具示例:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\tikzset{
    box/.style={rectangle, text centered, minimum height=3em},
    narrowbox/.style={box,text width=4cm,draw,thick},
    line/.style={draw, thick, -Stealth}
}
\begin{document}
    \begin{tikzpicture}[auto]
        \node [box]                                     (inv)      {};
        \node [box, below=0.5cm of inv]                 (deter)    {};
        \coordinate [below=0.5cm of deter]              (vuoto1);
        \node [narrowbox, below=0.5cm of vuoto1]        (meth2)    {};
        \node [narrowbox, left=0.5cm of meth2]          (meth1)    {};
        \node [narrowbox, right=0.5cm of meth2]         (meth3)    {};
        \node [narrowbox, below=0.5cm of meth3]         (select1)  {};  
        \node [narrowbox, below=0.5cm of meth1]         (select)   {};
        \node [narrowbox, below=0.5cm of select]        (select2)  {}; 
        \node [box, below=4.5cm of meth2]               (decide)   {Shorter};
        \node [box, below=0.5cm of decide]              (inter)    {};

        \path [line] (inv)      --    (deter);
        \path [line] (deter)    --    (meth2);
        \path [line] (vuoto1)   -|    (meth1);
        \path [line] (vuoto1)   -|    (meth3);
        \path [line] (meth1)    --    (select);
        \path [line] (select)   --    (select2);
        \path [line] (select2)  --    (select.south |- decide.north);
        \path [line] (meth2)    --    (decide);
        \path [line] (meth3)    --    (select1);
        \path [line] (select1)  --    (meth3.south |- inter.north);
        \path [line] (decide)   --    (inter);

        % draw rectangles around top and bottom nodes
        \foreach \N in {inv,deter,decide,inter}
        \draw [thick] (\N.north -| meth1.west) rectangle (\N.south -| meth3.east);
    \end{tikzpicture}
\end{document}

下图中我尝试画了一些线,这样更容易理解,目的是得到红色箭头的位置,并像蓝线一样缩短框宽度。

在此处输入图片描述

答案1

chains使用提供的框架(例如,甚至是树)来执行此操作会更简单。但是,只需进行最小的更改:

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{arrows.meta,positioning}
\tikzset{
    box/.style={rectangle, text centered, minimum height=3em,text width=130mm,draw},
    narrowbox/.style={box,text width=4cm,draw,thick},
    line/.style={draw, thick, -Stealth}
}
\begin{document}
\begin{tikzpicture}[auto]
  \node [box]                                     (inv)      {i};
  \node [box, below=0.5cm of inv]                 (deter)    {d};
  \coordinate [below=0.5cm of deter]              (vuoto1);
  \node [narrowbox, below=0.5cm of vuoto1]        (meth2)    {m2};
  \node [narrowbox, anchor=west]          (meth1) at (meth2 -| deter.west)    {m1};
  \node [narrowbox, anchor=east]         (meth3) at (meth2 -| deter.east)    {m3};
  \node [narrowbox, below=0.5cm of meth3]         (select1)  {s1};
  \node [narrowbox, below=0.5cm of meth1]         (select)   {s};
  \node [narrowbox, below=0.5cm of select]        (select2)  {s2};
  \node [box, text width={(2/3)*130mm}, below=4.5cm of meth1.south west, anchor=north west]               (decide)   {Shorter};
  \node [box, below=0.5cm of decide.south west, anchor=north west]              (inter)    {it};

  \path [line] (inv)      --    (deter);
  \path [line] (deter)    --    (meth2);
  \path [line] (vuoto1)   -|    (meth1);
  \path [line] (vuoto1)   -|    (meth3);
  \path [line] (meth1)    --    (select);
  \path [line] (select)   --    (select2);
  \path [line] (select2)  --    (select.south |- decide.north);
  \path [line] (meth2)    --    (decide.north -| meth2);
  \path [line] (meth3)    --    (select1);
  \path [line] (select1)  --    (meth3.south |- inter.north);
  \path [line] (decide.south)   --    (inter.north -| decide.south);

\end{tikzpicture}
\end{document}

调整事物

相关内容