Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

latex

tikz

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

like image 876
Marie Avatar asked Nov 17 '25 23:11

Marie


1 Answers

I would like to propose a modification to the code:

\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] ([xshift=1cm]v2.south) -- ([xshift=1cm]v2.south |- v1.north);
    \draw[-latex] ([xshift=-1cm]v3.south) -- ([xshift=-1cm]v3.south |- v1.north);
         
    \end{tikzpicture}
    \end{figure*}
\end{document}

Using this code for arrows allows you to avoid the unpleasant effect to have a portion of the arrow overlapped to the node border.

The result will be: clean arrows

instead of: overlapped arrows

like image 74
Mario Sernicola Avatar answered Nov 21 '25 09:11

Mario Sernicola