为直角连接器添加标签 -

为直角连接器添加标签 -

我尝试在 TikZ 图形中的直角连接器上添加标签。以下是我使用的代码:

\begin{tikzpicture}[every node/.style={minimum height={1.5cm},thick,align=center},node distance=2.5cm, auto]
\node[draw] (CC) {CC};
\node[draw, right= of CC] (PC) {PC};
\node[draw, dashed, below= of CC] (AP) {DP};
\node[draw, dashed, below= of AP] (SP) {SP};
\node[draw, below = of SP] (BD) {BD};
\draw[->] (CC) to node {DM} (AP);
\draw[->] (AP.west) |- ($(AP.west) - (2.0,0)$) |- (BD.west);
\draw[->] (PC) |- (SP);
\draw[->] (AP) to node {SPa} (SP);
\draw[->] (SP) to node {Al} (BD);
\end{tikzpicture}

这是正在输出的内容加上我想要放置的标签用红色标记。 在此处输入图片描述

这怎么可能呢?我尝试过像平常一样输入,{text}\draw[->] (AP.west) |- ($(AP.west) - (2.0,0)$) |- (BD.west);出现错误或标签放错了位置。

提前致谢!

答案1

node您可以在相应的路径中使用:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}

\begin{tikzpicture}[every node/.style={minimum height={1.5cm},thick,align=center},node distance=2.5cm, auto]
\node[draw] (CC) {CC};
\node[draw, right= of CC] (PC) {PC};
\node[draw, dashed, below= of CC] (AP) {DP};
\node[draw, dashed, below= of AP] (SP) {SP};
\node[draw, below = of SP] (BD) {BD};
\draw[->] (CC) to node {DM} (AP);
\draw[->] (AP.west) |- ($(AP.west) - (2.0,0)$) |- node[near start,swap] {Label} (BD.west);
\draw[->] (PC) |- (SP);
\draw[->] (AP) to node {SPa} (SP);
\draw[->] (SP) to node {Al} (BD);
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

对于垂直定位,您可以将($(node a)!x!(node b)$)修饰键与xshift键一起使用。

相应的行变为

\draw[->] (AP.west) -| ([xshift=-2cm]$(AP)!0.5!(BD)$) node[red,left] {Label} |- (BD.west);

这样,您就不必猜测需要输入多少班次。

相关内容