我正在使用 tikzpicture 在 Latex 中绘制节点之间的连接。但是,连接不太好。我想知道如何才能获得右侧所示的预期结果。目前,我使用了下面的代码,结果显示在左侧。提前谢谢
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption,subfig}
\usepackage{float}
\usepackage{xcolor}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path
\usepackage{tikz, xcolor}
\usetikzlibrary{shapes,arrows}
\usepackage[draft]{todonotes} % notes showed
\begin{document}
\begin{figure} [H]
\centering
\begin{tikzpicture}[node distance = 3cm, auto]
% Place nodes
\node [label=above: A](A) {\includegraphics[width=0.15\textwidth]{example-image-a}};
\node [label=below: B,below right=1cm and 1cm of A] (B) {\includegraphics[width=0.15\textwidth]{example-image-b}};
\node [label=above: C ,above right=1cm and 1cm of A] (C) {\includegraphics[width=0.15\textwidth]{example-image-c}};
\node [label=below: D,right = 1cm of B] (D) {\includegraphics[width=0.15\textwidth]{example-image-a}};
\node [label=above: E,right = 1cm of C] (E) {\includegraphics[width=0.15\textwidth]{example-image-b}};
\node [label=above: result1 ,right = 1cm of D] (result1){};
\node [label=above: result2 ,right = 1cm of E] (result2){};
\node [label=above: result3 ,above of= result1] (result3){};
% Draw arrow
\draw[line width=0.3mm,->] (A) to (B);
\draw[line width=0.3mm,->] (A) to (C);
\draw[line width=0.3mm,->] (B) to (D);
\draw[line width=0.3mm,->] (C) to (E);
\draw[line width=0.3mm,->] (D) to (result1);
\draw[line width=0.3mm,->] (E) to (result2);
\draw[line width=0.3mm,->] (E) to (result3);
\draw[line width=0.3mm,->] (D) to (result3);
\end{tikzpicture}
\captionsetup{labelfont={bf},font={color=blue}}
\caption{Test graph}
\label{fig:2n}
\end{figure}
\end{document}
答案1
您可以使用|-
和-|
结合--
\draw[line width=0.3mm,->] (A) -- ++(1.5cm,0) |- (B);
\draw[line width=0.3mm,->] (A) -- ++(1.5cm,0) |- (C);
\draw[line width=0.3mm,->] (E) -- ++(1.5cm,0) |- (result3);
\draw[line width=0.3mm,->] (D) -- ++(1.5cm,0) |- (result3);