[Tex/LaTex] Using tikz: two boxes, two parallel linking edges

paralleltikz-pgf

I'd like to have two boxes with text inside them atop one another with some vertical space, and with two parallel vertical edges linking them. With just one such linking edge, tikz makes it easy: \draw (node1) -- (node2); (where node1 and node2 specify the two boxes with text). There's got to be a bit of separation between them; however, I've tried using things like (node1) +(5pt,0) -- (node2) +(5pt,0) and frankly it isn't working. I've tried scoping with shift={(5pt,0),transform shape} and the shift was ignored. So, how should I do this? (FYI: there's addtional options on the edges specifying labels and arrows, but I don't believe that they're relevant to this).

Example of single link:

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}[yscale=-1]
    \node at (0,0) (node1) [shape=rectangle,fill=green] {box1};
    \node at (0,1) (node2) [shape=rectangle,fill=green] {box2};
    \draw (node1) -- (node2);
  \end{tikzpicture}
\end{document}

An ascii version…

.  +----+
.  |box1|
.  +----+
.   |  |
. 1 v  ^ 3
.   |  |
.  +----+
.  |box2|
.  +----+

(pls ignore the "."s, I needed them to get the code entry to work)

Thank you for your solutions! I'll definitely be trying them out.

Best Answer

If I understand the problem correctly, you may want to use the double and double distance keys.

As described in subsubsection 15.3.5 of the tikz documentation, using the double key in a \draw command produces a double line. You can also fine-tune the distance between the two lines with the double distance key; using the latter automatically enables double, as pointed out in Claudio's comment. See below.

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}

\begin{document}

 \begin{tikzpicture}[yscale=-1]
    \node at (0,0) (node1) [shape=rectangle,fill=green] {box1};
    \node at (0,1) (node2) [shape=rectangle,fill=green] {box2};
    \draw[double distance=5pt] (node1) -- (node2);
    \node at (0,2) (node3) [shape=rectangle,fill=green] {box1};
    \node at (0,3) (node4) [shape=rectangle,fill=green] {box2};
    \draw[double distance=10pt] (node3) -- (node4);
  \end{tikzpicture}

\end{document}

Edit: if you need different decorations, labels etc. for the two lines, you need to construct two distinct paths; see below. To draw an arrowhead at the middle of an path, I refer you to Alain Matthes's answer to Tikz: Arrowheads in the center.

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\tikzset{
    ->-/.style={decoration={
        markings,
        mark=at position .5 with {\arrow{>}}},postaction={decorate}},
    -<-/.style={decoration={
        markings,
        mark=at position .5 with {\arrow{<}}},postaction={decorate}},
}

\begin{document}

\def\mydbldist{5pt}
 \begin{tikzpicture}[yscale=-1]
    \node at (0,0) (node1) [shape=rectangle,fill=green] {box1};
    \node at (0,1) (node2) [shape=rectangle,fill=green] {box2};
    \draw[->-] ([xshift=-.5*\mydbldist]node1.south) -- ([xshift=-.5*\mydbldist]node2.north)
        node[pos=.5,anchor=east] {$1$};
    \draw[-<-] ([xshift=.5*\mydbldist]node1.south) -- ([xshift=.5*\mydbldist]node2.north)
        node[pos=.5,anchor=west] {$3$};
  \end{tikzpicture}

\end{document}