3

I'm looking for a way to construct the line (image attached showing 2 different possibilities) in Tikz without using a node at the junction point of the two line segments (horizontal and diagonal). I can make one of these for each position but would much prefer to use a re-usable solution which would just change: starting and ending position along with angle. Is there something which already does this? Something along the line of balloons for labelling parts in an assembly?

enter image description here

1 Answer 1

4

You could use this as a starting point. I defined two styles /- (diagonal first, then horizontal) and -d (horizontal first, then diagonal):

enter image description here

The code:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{
  /-/.style={
    to path={ (\tikztostart) --
      ( {$ (\tikztostart)!#1!(\tikztotarget) $} |-\tikztotarget)  -- 
      (\tikztotarget) \tikztonodes
    }
  },
  /-/.default=0.5,
  -d/.style={
    to path={ (\tikztostart) --
      ( {$ (\tikztostart)!#1!(\tikztotarget) $} |-\tikztostart)  -- 
      (\tikztotarget) \tikztonodes
    }
  },
  -d/.default=0.5
}

\begin{document}

\begin{tikzpicture}

\draw[/-,cyan,line width=1pt]
  (-4,0) to (-1,2) node[right] {A};
\draw[-d,magenta,line width=1pt]
  (-5,-2) node[left] {B} to (-1,0);

\coordinate (a) at (0,0);
\coordinate (b) at (3,2);
\coordinate (c) at (5,-2);

\draw[/-]
  (a) node[left] {a} to  (b) node[right] {b};
\draw[/-=0.25]
  (a) to (b);
\draw[/-=0.75]
  (a) to (b);

\draw[/-]
  (a) to (c) node[right] {c};
\draw[/-=0.25]
  (a) to (c);
\draw[/-=0.75]
  (a) to (c);

\begin{scope}[xshift=6cm]
\coordinate (a) at (0,0);
\coordinate (b) at (3,2);
\coordinate (c) at (5,-2);

\draw[-d]
  (a) node[left] {a} to  (b) node[right] {b};
\draw[-d=0.25]
  (a) to (b);
\draw[-d=0.75]
  (a) to (b);

\draw[-d]
  (a) to (c) node[right] {c};
\draw[-d=0.25]
  (a) to (c);
\draw[-d=0.75]
  (a) to (c);
\end{scope}

\end{tikzpicture}

\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .