2

How can I draw two horizontal arrow lines to each direction from one rectangle to another. Rectangles are of different heights and I want to keep both arrows horizontal.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{calc,decorations.markings}

\begin{document}

\begin{figure} \centering
\begin{tikzpicture}[ node distance = 1cm and 2cm, document/.style = {rectangle, draw, rounded corners, fill=orange!10, minimum width=1cm, minimum height=1cm, align=center}, document2/.style = {rectangle, draw, rounded corners, fill=orange!10, minimum width=1cm, minimum height=4cm, align=center}, arrow/.style = {thick,-stealth} ]

\node   (a1)    [document]                                          {abc};
\node   (a2)    [document2, right=4cm of a1]                        {def};
\path [draw, arrow] (a1)        --  node    [text width=2cm, midway, anchor=north]  {going left} (a2);  

\end{tikzpicture}

\end{figure} \end{document}

enter image description here

Bernard
  • 271,350
pba
  • 527
  • 5
  • 10

2 Answers2

3

Edit: added are edges labels. For them is used quotes library:

enter image description here

\documentclass[margin=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}

\begin{document} \begin{tikzpicture}[ node distance = 1cm and 4cm, N/.style = {draw, rounded corners, fill=orange!10, minimum height=#1, minimum width=1cm}, ar/.style = {draw=red, thick, -Straight Barb}, every edge quotes/.append style = {font=\footnotesize} ] \node (a1) [N=10mm] {abc}; \node (a2) [N=40mm, right=of a1] {def}; % \draw[ar] (a1.10) to["going right"] (a1.10 -| a2.west); \draw[ar] (a2.190) to["going left"] (a2.190 -| a1.east); \end{tikzpicture} \end{document}

Addendum: Considering OP comment (after almost one year, I didn't see comment before :-( ):

\documentclass[margin=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}

\begin{document} \begin{tikzpicture}[ node distance = 1cm and 4cm, N/.style = {draw, rounded corners, fill=orange!10, minimum height=#1, minimum width=1cm}, ar/.style = {draw=red, thick, -Straight Barb}, every edge quotes/.append style = {font=\footnotesize, text=red, near start} ] \node (a1) [N=10mm] {abc}; \node (a2) [N=40mm, right=of a1] {def}; % \draw[ar] (a1.15) edge["going right"] (a1.15 -| a2.west) (a2.195) to ["going left"] (a2.195 -| a1.east); \end{tikzpicture} \end{document}

enter image description here

Zarko
  • 296,517
  • Thank you very much. Can you also let us know how can we put text such as "going left" and "going right" aligned to left and right of the arrow lines? – pba Jan 09 '21 at 15:42
3

Following solution is a little more verbose than Zarko's one, but it allows to easily control the distance between parallel lines.

\documentclass[margin=2]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}

\begin{document} \begin{tikzpicture}[ node distance = 1cm and 4cm, N/.style = {draw, rounded corners, fill=orange!10, minimum height=#1, minimum width=1cm}, ar/.style = {draw=red, thick, -Straight Barb} ] \node (a1) [N=10mm] {abc}; \node (a2) [N=40mm, right=of a1] {def}; % \draw[ar] ([yshift=1mm]a1.east) coordinate (aux1) -- (aux1 -| a2.west); \draw[ar] ([yshift=-1mm]a2.west) coordinate (aux2) -- (aux2 -| a1.east); \end{tikzpicture} \end{document}

enter image description here

Update: Adding labels above and below arrows

\documentclass[margin=2]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}

\begin{document} \begin{tikzpicture}[ node distance = 1cm and 4cm, N/.style = {draw, rounded corners, fill=orange!10, minimum height=#1, minimum width=1cm}, ar/.style = {draw=red, thick, -Straight Barb} ] \node (a1) [N=10mm] {abc}; \node (a2) [N=40mm, right=of a1] {def}; % \draw[ar] ([yshift=1mm]a1.east) coordinate (aux1) node[above right, red]{going right} -- (aux1 -| a2.west); \draw[ar] ([yshift=-1mm]a2.west) coordinate (aux2) node[below left, red]{going left} -- (aux2 -| a1.east); \end{tikzpicture} \end{document}

enter image description here

Ignasi
  • 136,588
  • Thank you very much. Can you also let us know how can we put text such as "going left" and "going right" aligned to left and right of the arrow lines? – pba Jan 09 '21 at 15:37
  • @pba I've updated the answer with desired labels – Ignasi Jan 09 '21 at 19:48
  • Many thanks. I was experimenting with the positioning of labels, "above left", "above right", "below left", "below right" works but what can we use it to place them at centre? and may be after some designated space (say 4mm)? – pba Jan 10 '21 at 02:06
  • This may needs to be a seperate thread. I raised this question in another thread https://tex.stackexchange.com/questions/578274/how-to-align-multiple-line-text-over-arrows-in-multiple-ways. Request you to please look into the same as well. – pba Jan 10 '21 at 04:52