TikZ Chains - 分支后合并

TikZ Chains - 分支后合并

我是 LaTeXchains软件包的新手,再次尝试将 2 个(甚至更多)分支合并到一个节点中。我只知道一种非常不灵活的方法,如下面的代码片段所示。代码中已将有关该问题的解释作为注释添加(希望它能让问题更清楚)。

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{tikz-timing}
\usetikzlibrary{chains} 
\usetikzlibrary{decorations.markings}
\usetikzlibrary{external}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}[
box/.style={draw,rectangle,minimum width=10pt,minimum height=10pt},
arrow/.style={->},
]

\begin{scope}[
start chain,
>=stealth,
every join/.style={->},
skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}},
point/.style={on chain,join=by -,coordinate},
]

\node [point] {$$};
\node [box, on chain, join] (Start) {$A$};
\begin{scope}[start branch,node distance=4mm and 6mm]
\node [box, join, on chain=going above right] (L) {$B$};
\end{scope}
\begin{scope}[start branch,node distance=4mm and 6mm]
\node [box, join, on chain=going below right] (R) {$C$};
\end{scope}
% the next node line adds a node with relative distance to the 
% Start node but this is impractical for longer chains with many branches
% i want to "merge" two branches into a single one and then use 
% "on chain" again to go on
\node [box] (stream2) at ($(Start.east) + (23mm,0)$) {D};    
\draw[arrow] (L.east) -> ($(stream2.north west)$);
\draw[arrow] (R.east) -> ($(stream2.south west)$);  

\end{scope}
\end{tikzpicture}

\end{document}}

这有可能吗?我感谢所有提示和帮助。

答案1

我做的唯一改变是添加

\node [box, join, on chain=going above right] (D) {$D$};

到第二个范围,然后在最后使用

\绘制[箭头] (B) -> (D);

这让我

在此处输入图片描述

数学家协会

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{chains} 
\usetikzlibrary{decorations.markings}


\begin{document}

\begin{tikzpicture}[
box/.style={draw,rectangle,minimum width=10pt,minimum height=10pt},
arrow/.style={->},
]

\begin{scope}[
start chain,
>=stealth,
every join/.style={->},
skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}},
point/.style={on chain,join=by -,coordinate},
]

\node [box, on chain, join] (Start) {$A$};
\begin{scope}[start branch,node distance=4mm and 6mm]
\node [box, join, on chain=going above right] (B) {$B$};
\end{scope}
\begin{scope}[start branch,node distance=4mm and 6mm]
\node [box, join, on chain=going below right] (C) {$C$};
\node [box, join, on chain=going above right] (D) {$D$};
\end{scope}
\draw[arrow] (B) -> (D);


\end{scope}
\end{tikzpicture}

\end{document}

相关内容