2

I'm trying to make a path diagram for my thesis and I'm running into trouble right at the beginning: I want the arrows to end below the y-rectangles (meaning at the lower side of the rectangles). I just started using tikz and I can't find any solution on how to control where the path ends.

This is my code:

\documentclass[
12pt,
a4paper,
parskip=never,           % hier ist angegeben, dass kein Einrücken nach den Absätzen gemacht werden soll
captions=tableheading,
nooneline,               % Unterscheidung zwischen ein- und mehrzeiligen Über- bzw. Unterschriften abschalten
numbers=noenddot,
headings=small,
twoside,                 % da gebunden zweiseitig einstellen: innenrand dann größer als äußerer Rand
BCOR=10mm,
listof=flat,
]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\usetikzlibrary{shapes.geometric,arrows}
\usepackage{caption}

\tikzstyle{manifest} = [rectangle, minimum width = 1cm, minimum height = 1cm, text centered, draw = black]
\tikzstyle{growthparameters} = [circle, minimum width = 2cm, text centered, draw = black]
\tikzstyle{arrow} = [draw, thick, ->, >=stealth]


\begin{document}

\begin{tikzpicture}[node distance = 4cm]

\node (y1) [manifest] {$Y_{i1}$};
\node (y2) [manifest, right of = y1] {$Y_{i2}$};
\node (y3) [manifest, right of = y2] {$Y_{i3}$};
\node (y4) [manifest, right of = y3] {$Y_{i4}$};
\node (y5) [manifest, right of = y4] {$Y_{i5}$};
\node (y6) [manifest, right of = y5] {$Y_{i6}$};
\node (y7) [manifest, right of = y6] {$Y_{i7}$};
\node (y8) [manifest, right of = y7] {$Y_{i8}$};
\node (y9) [manifest, right of = y8] {$Y_{i9}$};
\node (y10) [manifest, right of = y9] {$Y_{i10}$};
\node (y11) [manifest, right of = y10] {$Y_{i11}$};
\node (y12) [manifest, right of = y11] {$Y_{i12}$};
\node (mu0) [growthparameters, below of = y2, yshift = -3cm] {$\mu_\alpha$};
\node (mu1) [growthparameters, below of = y5, yshift = -3cm] {$\mu_{\beta_1}$};
\node (mu2) [growthparameters, below of = y8, yshift = -3cm] {$\mu_{\beta_2}$};

\draw [arrow] (mu0) -- (y1);
\draw [arrow] (mu0) -- (y2) ;
\draw [arrow] (mu0) -- (y3) ;
\draw [arrow] (mu0) -- (y4) ;
\draw [arrow] (mu0) -- (y5) ;
\draw [arrow] (mu0) -- (y6) ;
\draw [arrow] (mu0) -- (y7) ;
\path [arrow] (mu0) -- (y8) ;
\draw [arrow] (mu0) -- (y9) ;
\draw [arrow] (mu0) -- (y10);
\draw [arrow] (mu0) -- (y11);
\draw [arrow] (mu0) -- (y12);

\draw [arrow] (mu1) -- (y4) ;
\draw [arrow] (mu1) -- (y5) ;
\draw [arrow] (mu1) -- (y6) ;
\draw [arrow] (mu1) -- (y7) ;
\draw [arrow] (mu1) -- (y8) ;
\draw [arrow] (mu1) -- (y9) ;
\draw [arrow] (mu1) -- (y10);
\draw [arrow] (mu1) -- (y11);
\draw [arrow] (mu1) -- (y12);

\draw [arrow] (mu2) -- (y10);
\draw [arrow] (mu2) -- (y11);
\draw [arrow] (mu2) -- (y12);

\end{tikzpicture}

\end{document}

This results in:

enter image description here

  • A very quick fix is to replace (y<i>) by (y<i>.south) in all the arrow paths. – user121799 Sep 12 '18 at 15:45
2

You can use anchors of nodes for your path ends, such as nodeName.south, nodeName.north, etc. Check the manual Section 17.5 and picture below: Node's anchors

For your problem, you can add .north in your lower nodes, and .south in your upper nodes.

\documentclass[
12pt,
a4paper,
parskip=never,           % hier ist angegeben, dass kein Einrücken nach den Absätzen gemacht werden soll
captions=tableheading,
nooneline,               % Unterscheidung zwischen ein- und mehrzeiligen Über- bzw. Unterschriften abschalten
numbers=noenddot,
headings=small,
twoside,                 % da gebunden zweiseitig einstellen: innenrand dann größer als äußerer Rand
BCOR=10mm,
listof=flat,
]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\usetikzlibrary{shapes.geometric,arrows}
\usepackage{caption}

\tikzstyle{manifest} = [rectangle, minimum width = 1cm, minimum height = 1cm, text centered, draw = black]
\tikzstyle{growthparameters} = [circle, minimum width = 2cm, text centered, draw = black]
\tikzstyle{arrow} = [draw, thick, ->, >=stealth]


\begin{document}

\begin{tikzpicture}[node distance = 4cm]

\node (y1) [manifest] {$Y_{i1}$};
\node (y2) [manifest, right of = y1] {$Y_{i2}$};
\node (y3) [manifest, right of = y2] {$Y_{i3}$};
\node (y4) [manifest, right of = y3] {$Y_{i4}$};
\node (y5) [manifest, right of = y4] {$Y_{i5}$};
\node (y6) [manifest, right of = y5] {$Y_{i6}$};
\node (y7) [manifest, right of = y6] {$Y_{i7}$};
\node (y8) [manifest, right of = y7] {$Y_{i8}$};
\node (y9) [manifest, right of = y8] {$Y_{i9}$};
\node (y10) [manifest, right of = y9] {$Y_{i10}$};
\node (y11) [manifest, right of = y10] {$Y_{i11}$};
\node (y12) [manifest, right of = y11] {$Y_{i12}$};
\node (mu0) [growthparameters, below of = y2, yshift = -3cm] {$\mu_\alpha$};
\node (mu1) [growthparameters, below of = y5, yshift = -3cm] {$\mu_{\beta_1}$};
\node (mu2) [growthparameters, below of = y8, yshift = -3cm] {$\mu_{\beta_2}$};

\draw [arrow] (mu0.north) -- (y1.south);
\draw [arrow] (mu0.north) -- (y2.south) ;
\draw [arrow] (mu0.north) -- (y3.south) ;
\draw [arrow] (mu0.north) -- (y4.south) ;
\draw [arrow] (mu0.north) -- (y5.south) ;
\draw [arrow] (mu0.north) -- (y6.south) ;
\draw [arrow] (mu0.north) -- (y7.south) ;
\path [arrow] (mu0.north) -- (y8.south) ;
\draw [arrow] (mu0.north) -- (y9.south) ;
\draw [arrow] (mu0.north) -- (y10.south);
\draw [arrow] (mu0.north) -- (y11.south);
\draw [arrow] (mu0.north) -- (y12.south);

\draw [arrow] (mu1.north) -- (y4.south) ;
\draw [arrow] (mu1.north) -- (y5.south) ;
\draw [arrow] (mu1.north) -- (y6.south) ;
\draw [arrow] (mu1.north) -- (y7.south) ;
\draw [arrow] (mu1.north) -- (y8.south) ;
\draw [arrow] (mu1.north) -- (y9.south) ;
\draw [arrow] (mu1.north) -- (y10.south);
\draw [arrow] (mu1.north) -- (y11.south);
\draw [arrow] (mu1.north) -- (y12.south);

\draw [arrow] (mu2.north) -- (y10.south);
\draw [arrow] (mu2.north) -- (y11.south);
\draw [arrow] (mu2.north) -- (y12.south);

\end{tikzpicture}

\end{document}

enter image description here

3

A proposal using conditional to define which position should connect the line according to the node. I changed to the stadalone environment since size of the draw is too broad and I do not know what size it will have, but you can export it to your main document and size it with the graphicx package. Also change the direct lines by lines with corners with rounded edges. I do not know if it can be an alternative or have a better presentation, I think it's users taste.

RESULT: enter image description here

MWE:

\documentclass[tikz,border=15pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usetikzlibrary{shapes.geometric,arrows.meta,positioning}

\tikzstyle{manifest} = []
\tikzstyle{growthparameters} = []
\tikzstyle{arrow} = []

\begin{document}
    \begin{tikzpicture}[
        %Environment cfg
        %Environment styles
        manifest/.style={
            rectangle,
            draw,
            minimum width=1cm,
            minimum height=1cm,
            text centered,
        },
        growthparameters/.style={
            circle,
            draw,
            minimum width = 2cm,
            text centered
        },
        arrow/.style={
            draw,
            line width=1pt,
            ->,
            >={Stealth[length=7pt]},
            rounded corners=0.5cm
        }
    ]
        \foreach \n [count=\m from 0]in {1,...,12}{
            \def\NodeDistance{2cm}
            \node(y\n)[manifest] at (\m*\NodeDistance,0){$Y_{i\n}$};
        }

        \node (mu0) [growthparameters, below= 5 of y2] {$\mu_\alpha$};
        \node (mu1) [growthparameters, below= 5 of y5] {$\mu_{\beta_1}$};
        \node (mu2) [growthparameters, below= 5 of y8] {$\mu_{\beta_2}$};

        \foreach \n in {1,...,12}{
            \ifnum\n<4\draw[arrow] (mu0) -- ++(0,5-\n*0.1) -| (y\n);
            \else
            \draw[arrow] (mu0) -- ++(0,5-\n*0.1) -| (y\n.-120);
            \fi
        }
        \foreach \n in {4,...,12}{
            \draw[arrow] (mu1) -- ++(0,4-\n*0.1) -| (y\n);
        }
        \foreach \n in {10,...,12}{
            \draw[arrow] (mu2) -- ++(0,3.5-\n*0.1) -| (y\n.-60);
        }
    \end{tikzpicture}
\end{document}
2

Here is a proposal makes sure that the arrows always end at the southern border, but the position depends on where the arrow comes from. BTW, with \foreach you can avoid having to repeat things.

\documentclass[
12pt,
a4paper,
parskip=never,           % hier ist angegeben, dass kein Einrücken nach den Absätzen gemacht werden soll
captions=tableheading,
nooneline,               % Unterscheidung zwischen ein- und mehrzeiligen Über- bzw. Unterschriften abschalten
numbers=noenddot,
headings=small,
twoside,                 % da gebunden zweiseitig einstellen: innenrand dann größer als äußerer Rand
BCOR=10mm,
listof=flat,
]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\usetikzlibrary{shapes.geometric,arrows,babel,calc}
\usepackage{caption}

\tikzset{manifest/.style={rectangle, minimum width = 1cm, minimum height = 1cm, text centered, draw = black},
growthparameters/.style={circle, minimum width = 2cm, text centered, draw = black},
arrow/.style={draw, thick, ->, >=stealth}}

\tikzset{my arrow/.style={to path={let \p1=(\tikztostart),\p2=(\tikztotarget),
\n1={-90-0.5*(-90+(180-atan2(\y2-\y1,\x2-\x1)))}
in (\tikztostart) -- (\tikztotarget.\n1) \tikztonodes},-stealth}}

\begin{document}

\begin{tikzpicture}[node distance = 4cm]

\node (y1) [manifest] {$Y_{i1}$};
\node (y2) [manifest, right of = y1] {$Y_{i2}$};
\node (y3) [manifest, right of = y2] {$Y_{i3}$};
\node (y4) [manifest, right of = y3] {$Y_{i4}$};
\node (y5) [manifest, right of = y4] {$Y_{i5}$};
\node (y6) [manifest, right of = y5] {$Y_{i6}$};
\node (y7) [manifest, right of = y6] {$Y_{i7}$};
\node (y8) [manifest, right of = y7] {$Y_{i8}$};
\node (y9) [manifest, right of = y8] {$Y_{i9}$};
\node (y10) [manifest, right of = y9] {$Y_{i10}$};
\node (y11) [manifest, right of = y10] {$Y_{i11}$};
\node (y12) [manifest, right of = y11] {$Y_{i12}$};
\node (mu0) [growthparameters, below of = y2, yshift = -3cm] {$\mu_\alpha$};
\node (mu1) [growthparameters, below of = y5, yshift = -3cm] {$\mu_{\beta_1}$};
\node (mu2) [growthparameters, below of = y8, yshift = -3cm] {$\mu_{\beta_2}$};

\foreach \X in {1,...,12} 
{\draw  (mu0) edge[my arrow] (y\X);}

\foreach \X in {4,...,12} 
{\draw  (mu1) edge[my arrow] (y\X);}

\foreach \X in {10,11,12} 
{\draw  (mu2) edge[my arrow] (y\X);}

\end{tikzpicture}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.