创建等距 Tikz 图形

创建等距 Tikz 图形
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
            calc, chains, 
            positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 7mm and 9mm,
  start chain = A going right,
   box/.style = {draw, minimum size=7mm,
                 align=center, on chain},
every edge/.style = {draw, -Straight Barb, semithick, shorten >=1mm, shorten <=1mm}
                        ]
\foreach \i in {this is really long, short, s, this is medium}
    \node[box] {\i}; % used at first image    node names: A-\i
%   \node[box] {\i\\}; % used at second image
\node[box,below=of $(A-2.south)!0.5!(A-3.south)$]   {it stretches quite a bit};
%\node[box,below=of $(A-2.south)!0.5!(A-3.south)$]   {5\\};
%
\draw[transform canvas={yshift=1mm}]
    (A-1) edge (A-2) ;
    \draw[transform canvas={yshift=0mm}]
    (A-2) edge (A-3)    (A-3) edge (A-4);
\draw[transform canvas={yshift=-1mm}]
            (A-2) edge (A-1);
\draw   (A-1.south) edge (A-5)  (A-2.south) edge (A-5)
        (A-3.south) edge (A-5)  (A-4.south) edge (A-5);
    \end{tikzpicture}
\end{document}

@Zarko 在相关文章中提供了很大帮助:创建此图

答案1

如果您的问题是获得大小相同且宽度刚好足以容纳最宽文本的节点,则可以使用eqparbox

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
            calc, chains, 
            positioning}
\usepackage{eqparbox}
\newbox\eqnodebox
\tikzset{equal size/.style={execute at begin
    node={\setbox\eqnodebox=\hbox\bgroup},
    execute at end node={\egroup\eqmakebox[#1][c]{\copy\eqnodebox}}},
    equal size/.default=A}

\begin{document}
    \begin{tikzpicture}[
node distance = 7mm and 9mm,
  start chain = A going right,
   box/.style = {draw, 
                 align=center, on chain,
                 equal size%<-added
                 },
every edge/.style = {draw, -Straight Barb, semithick, shorten >=1mm, shorten <=1mm}
                        ]
\foreach \i in {this is really long, short, s, this is medium}
    \node[box] {\i}; % used at first image    node names: A-\i
\node[box,below=of $(A-2.south)!0.5!(A-3.south)$]   {it stretches quite a bit};
%
\draw[transform canvas={yshift=1mm}]
    (A-1) edge (A-2) ;
\draw[transform canvas={yshift=0mm}]
    (A-2) edge (A-3)    (A-3) edge (A-4);
\draw[transform canvas={yshift=-1mm}]
            (A-2) edge (A-1);
\draw   (A-1.south) edge (A-5)  (A-2.south) edge (A-5)
        (A-3.south) edge (A-5)  (A-4.south) edge (A-5);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

text width如果您心中有特定尺寸,则可以使用它。

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
            calc, chains, 
            positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 7mm and 9mm,
  start chain = A going right,
   box/.style = {draw, text width=5em,minimum height=2.5em,
                 align=center, on chain},
every edge/.style = {draw, -Straight Barb, semithick, shorten >=1mm, shorten <=1mm}
                        ]
\foreach \i in {this is really long, short, s, this is medium}
    \node[box] {\i}; % used at first image    node names: A-\i
%   \node[box] {\i\\}; % used at second image
\node[box,below=of $(A-2.south)!0.5!(A-3.south)$]   {it stretches quite a bit};
%\node[box,below=of $(A-2.south)!0.5!(A-3.south)$]   {5\\};
%
\draw[transform canvas={yshift=1mm}]
    (A-1) edge (A-2) ;
    \draw[transform canvas={yshift=0mm}]
    (A-2) edge (A-3)    (A-3) edge (A-4);
\draw[transform canvas={yshift=-1mm}]
            (A-2) edge (A-1);
\draw   (A-1.south) edge (A-5)  (A-2.south) edge (A-5)
        (A-3.south) edge (A-5)  (A-4.south) edge (A-5);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容