8

I want these arrows to be parallel.

Why isn't yshift working the same way on the start and end of the path?

Is there a better way to choose locations on the boxes? Is there an anchor for halfway up one edge of the box? What about the corners?

Thanks!!

\documentclass{standalone}

\usepackage{newtxtext}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}

  \tikzstyle{box} = [rectangle, draw, minimum height=6cm, text width=3cm, text centered, rounded corners]
  \tikzstyle{line} = [draw, -latex']
  
  \begin{tikzpicture}[node distance = 6em, auto]
    
    \node [box] (box-a) {BOX A};
    \node [box, right of=box-a, node distance=6cm] (box-b) {BOX B};
    
    \path [line] ([yshift=+5cm] box-a) -- node [midway, above] {Path 1 Above} node [midway, below] {Path 1 Below} ([yshift=+5cm] box-b);
    \path [line] ([yshift=-5cm] box-a) -- node [midway, above] {Path 2 Above} node [midway, below] {Path 2 Below} ([yshift=-5cm] box-b);
    
\end{tikzpicture}

\end{document}

MWE on GitHub

Capture of MWE

1
  • 1
    you could also chose the cardinal points on the nodes for examples 0 deg, 45 deg -- represented as box-a.0, box-a.45, etc and the corresponding points on box-b.180, box-b.135, etc -- see the answer below
    – js bibra
    May 27, 2021 at 0:14

3 Answers 3

9

Since the node is 6cm tall, add 5cm could be too much. Maybe is .5cm what you wish.

Is this what you want?

\documentclass[border=1pt]{standalone}

\usepackage{newtxtext}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}

  \tikzstyle{box} = [rectangle, draw, minimum height=6cm, text width=3cm, text centered, rounded corners]
  \tikzstyle{line} = [draw, -latex']
  
  \begin{tikzpicture}[node distance = 6em, auto]
    
    \node [box] (box-a) {BOX A};
    \node [box, right of=box-a, node distance=6cm] (box-b) {BOX B};
    
    \path [line] ([yshift=+.5cm] box-a.east) -- node [midway, above] {Path 1 Above} node [midway, below] {Path 1 Below} ([yshift=+.5cm] box-b.west);
    \path [line] ([yshift=-.5cm] box-a.east) -- node [midway, above] {Path 2 Above} node [midway, below] {Path 2 Below} ([yshift=-.5cm] box-b.west);
    
\end{tikzpicture}

\end{document}

enter image description here

1
  • 1
    Great, thanks. I didn't realize my scale was so far off.
    – Lucas
    May 27, 2021 at 8:16
9

You can use an auxiliar coordinate and perpendicular (|-, -|) references to fix the end.

\path [line] ([yshift=+5mm] box-a.east) coordinate (aux)--(aux-|box-b.west);

This is a path which starts at aux and stops at the intersection place where an horizontal line through aux and a vertical line through box-b.west cross.

\documentclass[border=2mm]{standalone}

\usepackage{newtxtext}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}

  \tikzstyle{box} = [rectangle, draw, minimum height=6cm, text width=3cm, text centered, rounded corners]
  \tikzstyle{line} = [draw, -latex']
  
  \begin{tikzpicture}[node distance = 6em, auto]
    
    \node [box] (box-a) {BOX A};
    \node [box, right of=box-a, node distance=6cm] (box-b) {BOX B};
    
    \path [line] ([yshift=+5mm] box-a.east) coordinate (aux)-- node [midway, above] {Path 1 Above} node [midway, below] {Path 1 Below} (aux-|box-b.west);
    \path [line] ([yshift=-5mm] box-a.east) coordinate (aux) -- node [midway, above] {Path 2 Above} node [midway, below] {Path 2 Below} (aux-|box-b.west);
    
\end{tikzpicture}

\end{document}

enter image description here

1
  • An elegant way to only specify one vertical offset. Thanks!
    – Lucas
    May 27, 2021 at 8:15
4

enter image description here

  \documentclass{standalone}

  \usepackage{newtxtext}
  \usepackage{tikz}
  \usetikzlibrary{shapes,arrows}

  \begin{document}

  \tikzstyle{box} = [rectangle, draw, minimum height=6cm, text width=3cm, text centered, rounded corners]
  \tikzstyle{line} = [draw, -latex']
  
  \begin{tikzpicture}[node distance = 6em, auto]
    
    \node [box] (box-a) {BOX A};
    \node [box, right of=box-a, node distance=6cm] (box-b) {BOX B};
    
    \foreach \i in {0,30,45, 55, 60,90}{
    \path [line] (box-a.\i) --  (box-b.180-\i);
    }
    \foreach \i in {0,30,45, 55, 60,90}{
    \path [line] (box-a.-\i) --  (box-b.180+\i);
    }
    
\end{tikzpicture}

\end{document}
2
  • Thanks for this answer. Does node.\i measure clockwise in degrees from node.east?
    – Lucas
    May 27, 2021 at 8:14
  • 1
    anti clockwise you can make out from the code
    – js bibra
    May 27, 2021 at 8:47

You must log in to answer this question.

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