Search code examples
latextikz

LaTex/tikZ: how to draw 2 vertical arrows from 2 nodes south to 1 node north?


How to draw vertical arrows from the nodes of variable 2 and variable 3 to variable 1?

\documentclass[jou]{apa7}
\usepackage{tikz}
\usepackage{fixltx2e}
\usetikzlibrary{shapes, shadows, arrows}
\usetikzlibrary{positioning}
\tikzset{mynode/.style={shape=rectangle, draw, align=center}
}

\begin{document}

\begin{figure*}
\begin{tikzpicture}
\node[mynode, text width=7cm,minimum height=1cm] (v1){Variable 1};
\node[mynode,above left= 2cm of v1, text width = 4cm, minimum height = 1cm, xshift=4cm](v2) {Variable 2};
\node[mynode,above right= 2cm of v1, text width=4cm, minimum height = 1cm, xshift=-4cm] (v3){Variable 3};

\draw[-latex] (v2.south) -- (v1.north);
\draw[-latex] (v3.south) -- (v1.north);
 
\end{tikzpicture}
\end{figure*}

\end{document}

Output with the above code:

enter image description here

Desired output:

enter image description here


Solution

  • Using -| will replace the diagonal line with horizontal and vertical segments:

    \documentclass[jou]{apa7}
    \usepackage{tikz}
    \usepackage{fixltx2e}
    \usetikzlibrary{shapes, shadows, arrows}
    \usetikzlibrary{positioning}
    \tikzset{mynode/.style={shape=rectangle, draw, align=center}
    }
    
    \begin{document}
    
    \begin{figure*}
    \begin{tikzpicture}
    \node[mynode, text width=7cm,minimum height=1cm] (v1){Variable 1};
    \node[mynode,above left= 2cm of v1, text width = 4cm, minimum height = 1cm, xshift=4cm](v2) {Variable 2};
    \node[mynode,above right= 2cm of v1, text width=4cm, minimum height = 1cm, xshift=-4cm] (v3){Variable 3};
    
    \draw[-latex] (v2.south) -| ([xshift=-2cm]v1.north);
    \draw[-latex] (v3.south) -| ([xshift=2cm]v1.north);
     
    \end{tikzpicture}
    \end{figure*}
    
    \end{document}
    

    enter image description here