9

I have two nodes

\node (A) {A};
\node [below=of A] (B) {B};

I can draw a line between them with

\draw (A) -- (B);

But I need two lines between them. If I'm using

\draw (A) -- (B);
\draw (B) -- (A);

it will draw the two lines on top of each other. Can I make some space between them? I have also tried (A.west) -- (B.west) but that's too far to the left. The two lines should be quite close to each other.

3 Answers 3

9

There are several ways, e.g.:

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

\begin{document}
\begin{tikzpicture}
  \node (A) {A};
  \node [below=of A] (B) {B};
  \draw[transform canvas={xshift=-1.5pt}] (A) -- (B);
  \draw[transform canvas={xshift=1.5pt}] (B) -- (A);
\end{tikzpicture}
\end{document}

Result

Or the shift can be added to the start and end points:

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

\begin{document}
\begin{tikzpicture}
  \node (A) {A};
  \node [below=of A] (B) {B};
  \foreach \s in {-1.5pt, 1.5pt} {
    \draw ([xshift=\s]A.south) -- ([xshift=\s]B.north);
  }
\end{tikzpicture}
\end{document}

Or a double line can be used, see the answer of Alenanno.

16

You can use the double key in the \draw options.

Output

figure 1

Code

\documentclass[tikz,margin=10pt]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
\node (A) {A};
\node [below=of A] (B) {B};

\draw[double] (A) -- (B);
\end{tikzpicture}
\end{document}

As Paul Stiverson noted in the comments, you can increase the distance by using double distance=.... Here's a short gif showing the various sizes from 1pt to 10pt.

enter image description here

11
  • You beat me to it! Note that you can change the spacing between the double lines by using something like: \draw [double, double distance between line centers=1.2em] (A) -- (B); Jun 22, 2015 at 16:12
  • @PaulStiverson Yes I know that but what I don't know is why the caps are showing very thin lines, do you know how to get rid of that? It's quite ugly. :D
    – Alenanno
    Jun 22, 2015 at 16:17
  • @Alenanno it is as always an anti-aliasing problem, depending on the viewer. You can check for example [this question](anti-aliasing) and the related answers.
    – Kpym
    Jun 22, 2015 at 16:48
  • @Kpym I think the link failed. :P
    – Alenanno
    Jun 22, 2015 at 17:00
  • @Alenanno sorry, here is the link.
    – Kpym
    Jun 22, 2015 at 17:14
1

two others solutions

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{positioning,calc,intersections}

\begin{document}


\begin{tikzpicture}

\begin{scope}
\node[draw] (A) at (0,0){A};
\node[draw,right=5em of A] (B)  {B};
\draw[-latex] (A.10)--(A.10-|B.west);
\draw[-latex] (B.-170)--(B.-170-|A.east);
\end{scope}

\begin{scope}[yshift=-2cm]
\node[draw] (A) at (0,0){A};
\node[draw,right=5em of A] (B)  {B};
\draw[-latex] (A) to [bend right=10] (B);
\draw[-latex] (B) to [bend right=10] (A);
\end{scope}


\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

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