Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm try to add a label to a right-angled connector in a TikZ figure. Below is the code I'm using:

\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}

This is what is being output plus the label I would like to put is marked in red. enter image description here

How could this be done? I've tried putting in the usual {text} in \draw[->] (AP.west) |- ($(AP.west) - (2.0,0)$) |- (BD.west); but I'm either getting an error or the label is being misplaced.

Thanks in advance!

share|improve this question
1  
Unrelated comment: Another way of creating that particular line is \draw[->] (AP.west) |- ++(-2.0,0) |- (BD.west);. Doesn't require the calc library. –  Torbjørn T. Dec 14 '12 at 22:29

2 Answers 2

up vote 7 down vote accepted

You can use a node in the corresponding path:

\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}

enter image description here

share|improve this answer

For vertical positioning you can use the ($(node a)!x!(node b)$) modifier together with the xshift key.

The corresponding line becomes

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

This way you don't have to guess how much shift you need to enter.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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