8

I know how to draw parallel lines between two nodes that are either aligned horizontally or vertically.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}[myn/.style={circle,draw,inner sep=0.25cm,outer sep=3pt}]
  \node[myn] (A) at (0,0) {A};
  \node[myn] (B) at (5,0) {B};
  \node[myn] (C) at (5,3) {C};
  \node[myn] (Z) at (10,-5) {Z};

  \draw[->] (A.10) -- (B.170);
  \draw[<-] (A.-10) -- (B.190);

  \draw[->] (B.80) -- (C.-80);
  \draw[<-] (B.100) -- (C.-100);

\end{tikzpicture}

\end{document}

enter image description here

What I'd like to know is how to do something similar between nodes that are not so aligned such as between nodes A and Z in the above diagram where I don't necessarily know exactly where Z will be placed beforehand.

I'm able to get something like

  \path let \p1=($(Z)-(A)$),
            \n1={atan(\y1/\x1)},
            \n2={\n1+180},
            \n3={\n1+90},
            \n4={1ex*cos(\n3)},
            \n5={1ex*sin(\n3)}
        in
        [draw,blue] ([yshift=\n5,xshift=\n4]A.\n1) -- ([yshift=\n5,xshift=\n4]Z.\n2);

to work, but this just seems way more complicated than necessary (or, is it?).

Incidentally, though this is perhaps starting to look like a commutative diagram, that's not what it's supposed to be.

8

Here is a suggestion using partway modifiers:

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

% Syntax:
% \DoublLine[half of the double line distance]{first node}{second node}{options line 1}{options line 2}
\newcommand\DoubleLine[5][3pt]{%
  \path(#2)--(#3)coordinate[at start](h1)coordinate[at end](h2);
  \draw[#4]($(h1)!#1!90:(h2)$)--($(h2)!#1!-90:(h1)$);
  \draw[#5]($(h1)!#1!-90:(h2)$)--($(h2)!#1!90:(h1)$);
}

\begin{document}
\begin{tikzpicture}[myn/.style={circle,draw,inner sep=0.25cm,outer sep=3pt}]
  \node[myn] (A) at (0,0) {A};
  \node[myn] (B) at (5,0) {B};
  \node[myn] (C) at (5,3) {C};
  \node[myn] (Z) at (10,-5) {Z};
% double lines:
  \foreach \p in {A,C,Z}{
    \DoubleLine{B}{\p}{<-,red}{->,blue}
  }
\end{tikzpicture}
\end{document}

enter image description here

  • The at start and at end syntax is what I needed to learn about. Thank you. – A.Ellett Jul 12 '14 at 15:40
0

Just for fun with PSTricks.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node}
\begin{document}
\begin{pspicture}[radius=15pt,nodesep=5pt,showgrid](8,8)
    \rput(2,6){\Circlenode{a}{A}}
    \rput(6,2){\Circlenode{b}{B}}
    \ncline[linecolor=red]{a}{b}
    \ncline[offset=6pt,linecolor=green]{a}{b}
    \ncline[offset=-6pt,linecolor=blue]{a}{b}
\end{pspicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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