3

I would like to add some labels onto chain join arrow lines.

Any command can be added to join styles with labels?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta,chains}
\begin{document}
\begin{tikzpicture}[
    node distance=1.5cm,
    arrow/.style={->, >=Stealth, thick},
    every on chain/.append style={draw,join,rounded corners,minimum width=2cm, minimum height=1cm, align=center},
    every join/.style={arrow},
    start chain=C1 going right,
    ]

\def\nodes{ A/A2B, B/B2C, C/C2A% } \foreach \name/\label [count=\i] in \nodes { \typeout{debugme \label} \node[on chain,join] (N\i) {\name}; }

\end{tikzpicture} \end{document}

Output: enter image description here

lucky1928
  • 4,151
  • see the zarko's answer here https://tex.stackexchange.com/questions/522212/tikz-arrows-and-blocks/522230#522230 – pascal974 Jan 11 '24 at 04:48
  • Your nodes are already named C1-1, C1-2, … by the chains library, by the way. The first is also available under the name C1-begin and the currently last under C1-end. Since you've added join to both the every on chain style as well as the options of the node, the arrows are actually drawn twice. Since the answers also use the join with the node, I'd remove the join from the every on chain style. – Qrrbrbirlbel Jan 11 '24 at 15:25

2 Answers2

6

From js bibra's answer, with chain-end and chain-begin

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                %positioning,
                % scopes,
                quotes,}
\begin{document}
    \begin{tikzpicture}[
        node distance=1.5cm,
        arrow/.style={->, >=Stealth, thick},
        every on chain/.append style={draw,join,rounded corners,minimum width=2cm, minimum height=1cm, align=center},
        every join/.style={arrow},
        start chain=going right,
        ]
    \def\nodes{
        A/,
        B/A2B,
        C/B2C%
    }
    \foreach \name/\label [count=\i] in \nodes {
        % \node[on chain,join=by {->,"\label"}] (N\i) {\name};
        \node[on chain,join=by {"\label"}] (N\i) {\name};
        }    
    \draw [arrow] (chain-end.south) -- ++(0,-1.) -|  (chain-begin.south) node[above,pos=0.25]{C2A};
\end{tikzpicture}

\end{document}

enter image description here

pascal974
  • 4,652
  • nice answer +1 but can we get the feedback loop into the chain syntax that is where I got stuck – js bibra Jan 11 '24 at 11:53
  • @jsbibra \chainin (<name>-begin) [join=by {<special>, "C2A"}]; where <name> is the name of the chain (chain in this answer, C1 in OP's MWE, though N1 can be used) and <special> is any option that are allowed for the join (which is just an edge), so any to path specification, etc. Though, this makes chain-end the first node again. You can also join=with <name>-begin by {<special>, "C2A"} on the last node but have to reverse the direction, I guess. Best be done with a late option so we don't have to check this inside the loop. – Qrrbrbirlbel Jan 11 '24 at 13:21
  • Nice answer, which part need the quotes library? – lucky1928 Jan 11 '24 at 20:52
  • @lucky1928 For join=by {"\label"} – pascal974 Jan 12 '24 at 05:17
3

A partial answer since the last node shows up as an empty box- could not find out how to delete it - probably some of the veterans will step in to help

Output

enter image description here

MWE

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,chains,positioning,scopes,quotes}
\begin{document}
    \begin{tikzpicture}[
        node distance=1.5cm,
        arrow/.style={->, >=Stealth, thick},
        every on chain/.append style={draw,join,rounded corners,minimum width=2cm, minimum height=1cm, align=center},
        every join/.style={arrow},
        start chain=C1 going right,
        ]
    \def\nodes{
        A/,
        B/A2B,
        C/B2C,
          /C2A%
    }
    \foreach \name/\label [count=\i] in \nodes {
        \node[on chain,join=by {-&gt;,&quot;\label&quot;}] (N\i) {\name};
    }

\end{tikzpicture}

\end{document}

js bibra
  • 21,280
  • Defining ch-4/.style=coordinate and then doing ch-\i/.try would be the easiest while not very flexible. We could also allow some special case of \name that would trigger this, e.g. empty if no other node could be empty. A special treatment for the last item in PGFFor would be nice. – Qrrbrbirlbel Jan 11 '24 at 10:05