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.

Jamgreen
  • 3,687

3 Answers3

15

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

Alenanno
  • 37,338
  • 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); – Paul Stiverson Jun 22 '15 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 '15 at 16:17
  • @Alenanno it is as always an anti-aliasing problem, depending on the viewer. You can check for example this question and the related answers. – Kpym Jun 22 '15 at 16:48
  • @Kpym I think the link failed. :P – Alenanno Jun 22 '15 at 17:00
  • @Alenanno sorry, here is the link. – Kpym Jun 22 '15 at 17:14
  • @Kpym I see, thanks for the link. Although I'm not sure they apply to this case. – Alenanno Jun 22 '15 at 17:57
  • @Alenanno it is. Double line is equivalent two lines drawn one over the other. Try this \draw[thick, black] (A) -- (B); \draw[thin, white] (A) -- (B);. The black line is 'longer' because of anti-aliasing. If you transform your pdf to bitmap using ghostscript (without anti-aliasing), there will be no this very thin line. – Kpym Jun 22 '15 at 18:34
  • @Kpym So it's not actually there and just an artifact in my viewer? – Alenanno Jun 22 '15 at 18:35
  • @Alenanno yes ! – Kpym Jun 22 '15 at 18:36
  • @Kpym Which one do you use? I have Skim and my AA is enabled. Odd. – Alenanno Jun 22 '15 at 19:08
  • @Alenanno as far as I know AA is enabled in all viewers. Only pdf2bitmap converters like ghostscript, Photoshop and Acrobat export to PNG can get rid of it. – Kpym Jun 22 '15 at 19:21
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.

Alenanno
  • 37,338
Heiko Oberdiek
  • 271,626
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

rpapa
  • 12,350