0
\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 was a big help in a related post: Creating This Figure

1
  • What is the question here? Do you want to have all nodes to have the equal size? If so, you can use the text width key, add e.g. text width=5em to the definition of box.
    – user194703
    Feb 20, 2020 at 18:18

1 Answer 1

2

If your question is to obtain equally sized nodes that are just wide enough to fit the widest text, you can use 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}

enter image description here

You can use text width if you have a specific size in mind.

\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}

enter image description here

2
  • amazing thank you so much. is it possible to add some vertical space between the arrows and the box on the bottom--by shifting the bottom box down slightly? I try \baselineskip but it did not work out
    – bvowe
    Feb 20, 2020 at 19:51
  • @bvowe Sure. The distance is controlled by node distance = 7mm and 9mm, where the first value (7mm) indicates the vertical distances. You could use e.g. node distance = 12mm and 9mm,.
    – user194703
    Feb 20, 2020 at 20:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .