2

For example, the image:

enter image description here

can be drawn with following MWE:

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

\begin{document}
    \begin{tikzpicture}[
    node distance = 7mm and 7mm,
    start chain = going right,
base/.style = {draw, minimum size=7mm},
 box/.style = {base, on chain, join=by ->}
                        ]
\coordinate (a) at (0,-1);
\node (n1)  [box]   at (0,0) {A};
\node (n2)  [box]   {B};
\node (n3)  [box]   {C};
\node (n4)  [base]   at (a -| n2) {D};
\draw[red,->]   (n3) |- (n4);
\draw[red,->]   (n4) -| (n1);
    \end{tikzpicture}
\end{document}

Now, for some reason I like to have only one definition for nodes and draw above image again:

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

\begin{document}  
    \begin{tikzpicture}[
    node distance = 7mm and 7mm,
    start chain = going right,
box/.style = {draw, minimum size=7mm,
              on chain, join=by ->}
                        ]
\coordinate (a) at (0,-1);
\node (n1)  [box]   at (0,0) {A};
\node (n2)  [box]   {B};
\node (n3)  [box]   {C};
\node (n4)  [box]   at (a -| n2) {D};
\draw[red,->]   (n3) |- (n4);
\draw[red,->]   (n4) -| (n1);
    \end{tikzpicture}
\end{document}

Result is expected wrong:

enter image description here

Question: is it possible to say, that node "D" in above MWE is not on the chain? For example as

\node (n4)  [box, suppress chain]   at (a -| n2) {D};

similarly as it can be discontinued join between nodes in chain with definition of new option:

\tikzset{suppress join/.code={\def\tikz@after@path{}}}

and used as

\node (n4)  [box, suppress join]   at (a -| n2) {D};

I looked in TikZ documentation, where is described chainin (page 5449), but didn't find anything with opposite action.

  • What is the desired output? Could you provide a picture? – Dr. Manuel Kuehner Jul 13 '17 at 23:50
  • 1
    @Dr.ManuelKuehner I think he want to get the first picture with code similar to the second (without base/.style definition) – koleygr Jul 13 '17 at 23:57
4

Something like this?

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains, positioning}
\begin{document}
\makeatletter
\tikzset{
  suppress join/.code={\def\tikz@after@path{}},
  off chain/.code={\def\tikz@lib@on@chain{}}%
}
\makeatother
\begin{tikzpicture}[
  node distance = 7mm and 7mm,
  start chain = main going right,
  box/.style = {draw, minimum size=7mm, on chain, join=by ->}
  ]
  \coordinate (a) at (0,-1);
  \node (n1)  [box]   at (0,0) {A};
  \node (n2)  [box]   {B};
  \node (n3)  [box]   {C};
  \node (n4)  [suppress join, off chain, box]   at (a -| n2) {D};
  \draw[red,->]   (n3) |- (n4);
  \draw[red,->]   (n4) -| (n1);
\end{tikzpicture}
\end{document}

off chain

Note that the order matters here: off chain must be before box. You can then continue the chain, should you so desire.

\begin{tikzpicture}[
  node distance = 7mm and 7mm,
  start chain = main going right,
  box/.style = {draw, minimum size=7mm, on chain, join=by ->}
  ]
  \coordinate (a) at (0,-1);
  \node (n1)  [box]   at (0,0) {A};
  \node (n2)  [box]   {B};
  \node (n3)  [box]   {C};
  \node (n4)  [suppress join, off chain, box]   at (a -| n2) {D};
  \node [box] {E};
  \draw[red,->]   (n3) |- (n4);
  \draw[red,->]   (n4) -| (n1);
\end{tikzpicture}

continuation

Note, however, that the chains library is considered deprecated.

  • Dear @cfr, yes. I looking for something like this. Thank you very much! By the way, the off chain is sufficient. If the node is not in chain anymore, then macrojoin is not active in this node, so the suppress join is superfluous in this case :) – Zarko Jul 14 '17 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.