Simplify TiKz chain diagram

TiKz chain is amazing tool,I am reading Chains with labeled edges example.

This example use matrix to place nodes, then use chain to connect it together. it's fine of course but I am thinking about if we can just place the nodes and then the chain will connect it automatically.

So I just write a simple example:

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%

\usetikzlibrary{arrows,chains,matrix,positioning,scopes}
\makeatletter
\tikzset{join/.code=\tikzset{after node path={%
\ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)%
edge[every join]#1(\tikzchaincurrent)\fi}}}
\makeatother
\tikzset{>=stealth',every on chain/.append style={join},
every join/.style={->}}
\tikzstyle{labeled}=[execute at begin node=$\scriptstyle, execute at end node=$]

\begin{document}
\begin{tikzpicture}
\node (A) {A};
\node [right=of A] (B) {B};
{ [start chain] \chainin (A);
\chainin (B) [join={node[above,labeled] {\eta_1}}];;
}
\end{tikzpicture}
\end{document}


It works perfect now but I am wondering if we can combine the node statements with the draw statement together. Maybe looks like below (it doesn't work of course now)!

\begin{tikzpicture}
{ [start chain] \chainin \node (A) {A};;
\chainin \node [right=of A] (B) {B}; [join={node[above,labeled] {\eta_1}}];;
}
\end{tikzpicture}


Is it possible to make it work?

You can simply say on chain to make a node joined to a chain. And also with TikZ v3.00 it is easier to add labels to edges.

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,chains,positioning,scopes,quotes}
\begin{document}
\begin{tikzpicture}[>=stealth']
{[start chain]
\node[on chain] (A) {A};
\node[on chain,join=by {->,"$\eta_1$"},right=of A] (B) {B};
\node[on chain,join=by {<-,"$\eta_2$"},right=of B] (C) {C};
\node[on chain,join=by {bend left,->,"$\int dx$"},right=of C] (D) {D};
}
\end{tikzpicture}
\end{document}


• Great, so the example should be changed to use TiKz 3.00. :-). – Beatlej Mar 13 '15 at 19:40
• @Beatlej Not necessarily. With that example it works pretty OK. Note that it is from 2011 so allow for some decay – percusse Mar 13 '15 at 20:52