答案1
你可以用这个作为起点。我定义了两种样式/-
(先对角线,然后水平)和-d
(先水平,然后对角线):
代码:
\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}